动态链接Firebase仅在第一次使用

时间:2019-02-21 21:12:59

标签: swift firebase dynamic hyperlink firebase-dynamic-links

我正在我的iOS应用中添加Firebase动态链接。我根据文档进行了配置,直到现在为止。 在测试时,我注意到该链接打开了应用程序并调用了方法:

application (_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any]

工作!

但是当我再次单击链接(动态链接)时,它只是打开应用程序而没有调用该方法。

有人可以帮我吗?

我的代码:

private func application(_ application: UIApplication, continue userActivity: NSUserActivity,
                     restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
        let handled = DynamicLinks.dynamicLinks().handleUniversalLink(userActivity.webpageURL!) { (dynamiclink, error) in
//            let vc = NomeStoryboard.instance.configuracoes.instantiateViewController(withIdentifier: "idSB_ConfiguracoesApp_Onboard") as! ConfiguracoesAppPageViewController
//            UIApplication.shared.keyWindow?.rootViewController = vc
        }

        return handled
    }

    @available(iOS 9.0, *)
    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
        return application(app, open: url,
                           sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
                           annotation: "")
    }

    func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
            // Handle the deep link. For example, show the deep-linked content or
            // apply a promotional offer to the user's account.
            // ...
            return true
        }
        return false
    }
}

1 个答案:

答案 0 :(得分:0)

  1. 确保didFinishLaunchingWithOptions返回true。
  2. 看起来您的continueUserActivity版本稍旧-也许尝试使用更现代的签名:
    func application(_ application: UIApplication, continue userActivity: NSUserActivity, 
      restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool