点击推送通知会打开WKWebView,其中包含来自推送通知的链接

时间:2019-10-29 14:13:40

标签: ios swift url wkwebview

我的推送通知有问题。我想向我的推送通知发送一个链接,并将其用于我的WKWebView,但是我不知道该怎么做。我已经搜索了其他stackoverflow成员的一些开头,但不幸的是没有找到

TestingViewController.swift


class TestingViewController: UIViewController, WKUIDelegate, WKNavigationDelegate {

    @IBOutlet weak var webView: WKWebView!
    var extra: String?


    override func viewDidLoad() {
        super.viewDidLoad()

        webView.load(URLRequest(url: URL(string: extra!)!))
        webView.allowsBackForwardNavigationGestures = true
        webView.isUserInteractionEnabled = true


        let preferences = WKPreferences()
        preferences.javaScriptEnabled = true
        let configuration = WKWebViewConfiguration()
        configuration.preferences = preferences


}

AppDelegate.swift



    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler completionHandler: @escaping () -> Void) {
        let userInfo = response.notification.request.content.userInfo
        if let messageID = userInfo[gcmMessageIDKey] {
            print("Message ID: \(messageID)")
        }

       /* let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let tabBarVC = storyboard.instantiateViewController(withIdentifier: "TabBarViewController") as? TabBarViewController //{
        tabBarVC?.selectedIndex = 1
        self.window?.rootViewController = tabBarVC */

        let extraString = userInfo[gcmExtraKey]

        if extraString != nil {
            print("Extra Information: \(String(describing: extraString))")
        }

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: "TestingViewController") as! TestingViewController
        window?.rootViewController = vc



        print("--------------------USER INFO START---------------")
        print(userInfo)
        print("--------------------USER INFO ENDE---------------")
        completionHandler()
    }
}

我想通过单击推送通知,然后单击带有传递的URL的WKWebView来打开应用程序

先谢谢您

0 个答案:

没有答案