使用Swift的UIWebview - 从推送通知更改URL

时间:2017-03-05 10:23:41

标签: ios swift uiwebview

AppDelegate.swift

var vc = ViewController()
..

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> void) {
    if let pushUrl = userInfo[AnyHashable("pushUrl")] {
        let pushUrlStr = pushUrl as! String
        vc.changeWebviewURL(url: pushUrlStr)
    }
    completionHandler(UIBackgroundFetchResult.newData)
}

}

ViewController.swift

@IBOutlet weak var webVeiw: UIWebview!
..

func changeWebviewURL(url: String) {
    print("changeWebviewURL : \(url)")
    let request = URLRequest(url: URL(string: url)!)
    webView?.loadRequest(request)
}

推送通知功能正常,“changeWebViewURL”肯定会被调用。 但是为什么没有Webview响应呢?网址没有改变。

0 个答案:

没有答案