我正在使用一个智能应用程序横幅来推广一个应用程序,它工作得很好!但是,当我在智能应用程序横幅上点击时,我想加载我在webView中导航的链接(我使用的是WKWebView)。
以下是我在AppDelegate.swift文件中使用的代码:
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
}
它不起作用!
最佳答案
你可以试试这个:
应用内委派:
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
}
在视图控制器中:
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)
}
关于ios - 单击“智能应用程序横幅”时,如何加载我在webView中导航的链接?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37023375/