I am using a Smart App Banner to promote an application and it works well! However, I would like to load the link i’m navigating in my webView(I am using a WKWebView) when clinking on the Smart App Banner.
Here is the following code that I am using in my AppDelegate.swift file:
var vc = ViewController()
func application(application: UIApplication, openURL url: NSURL,sourceApplication: String?, annotation: AnyObject) -> Bool {
let url1 = NSURL(string:"\(url)")!
self.vc.webView!.loadRequest(NSURLRequest(URL: url1!))
return true
}
You can try this:
in app delegate:
func application(application: UIApplication, openURL url: NSURL,sourceApplication: String?, annotation: AnyObject) -> Bool {
let url1 = NSURL(string:"\(url)")!
NSNotificationCenter.defaultCenter().postNotificationName("OpenLinkNotification", object: url1)
return true
}
in the view controller:
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "methodOfReceivedNotification:", name:"OpenLinkNotification", object: nil)
...
}
...
func methodOfReceivedNotification(notification: NSNotification){
let url = notification.object as NSURL
self.vc.webView!.loadRequest(NSURLRequest(URL: url!))
}
override func viewDidDisappear(animated: Bool) {
NSNotificationCenter.defaultCenter().removeObserver(self)
}