通用链接,continueUserActivity和sourceApplication未被调用

时间:2017-07-28 09:21:23

标签: ios swift swift3 ios-universal-links

我终于设法做了通用链接,如果我点击链接它会打开我的应用程序。但它不会出现在继续用户活动或源应用程序中。因为我想将其重定向到特定的视图控制器。例如,如果我打开" https:// www.myWeb.com/forgotPassword"

它将重定向到forgotPasswordViewController,我需要阅读链接。

为什么它不会出现在继续用户活动中

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
    print(url)
    let urlHost : String = url.host as String!
    print("HELLO")

        let main : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let inner : ResetPasswordViewController = main.instantiateViewController(withIdentifier: "ResetPasswordViewController") as! ResetPasswordViewController
        self.window?.rootViewController = inner
        self.window?.makeKeyAndVisible()
        return true;



}

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {
    if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
        let url = userActivity.webpageURL!
        print(url)
        print("HELLO WORLD")
    }
    return true
}

这就是源应用程序发生的事情,有人可以告诉我为什么会这样吗?

sourceApplication

1 个答案:

答案 0 :(得分:6)

解决 这只是因为Data类型,我把AnyObject而不是Any。 但是编译器没有告诉我是否不能使用AnyObject

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
    print("Continue User Activity: ")
    if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
        let url = userActivity.webpageURL!
        print(url.absoluteString)
        //handle url
    }
    return true
}