This is an update of the Example above to take into account some changes in Xcode Version 9.0 (9A235) & Swift 4. , NotificationCenter Observers to swift 4 syntax and moved Objective C APIs to Swift APIs i.e NSURLRequest(url: theUrl!) to URLRequest(url: theUrl!)
Changing the Objective C API will help avoid using @objc inference.
TheSwift 3 compiler infers @objc behind the scenes on any Objective C api calls/functions for you. Swift 4 does not and you would need to add them your self or use the conversion tool when opening and older project.
Google for this if you need more info.
So for example.
Old Observer:
NotificationCenter.default.addObserver(self, selector: #selector(enterBackground), name: NSNotification.Name("UIApplicationWillResignActiveNotification"), object: nil)
Old function :
func enterBackground() {
print("call 1")
self.webView!.evaluateJavaScript("HYPE.documents['testCall'].showSceneNamed('splashScene', HYPE.documents['testCall'].kSceneTransitionCrossfade, 0.2);", completionHandler:nil )
}
function with @objc inference and using old observer
@objc func enterBackground() {
print("call 1")
self.webView!.evaluateJavaScript("HYPE.documents['testCall'].showSceneNamed('splashScene', HYPE.documents['testCall'].kSceneTransitionCrossfade, 0.2);", completionHandler:nil )
}
New observer and New function
NotificationCenter.default.addObserver(forName:Notification.Name(rawValue:"UIApplicationWillResignActiveNotification"),
object:nil, queue:nil,
using:enterBackground)
func enterBackground(notification:Notification) -> Void {
print("call 1")
webView!.evaluateJavaScript("HYPE.documents['testCall'].showSceneNamed('splashScene', HYPE.documents['testCall'].kSceneTransitionCrossfade, 0.2);", completionHandler:nil )
}
Everything works the same.
iOSHypeCalls_v2_swift4.zip (299.7 KB)