动态链接仅在模拟器中起作用,而在实际设备上不起作用

时间:2019-02-03 20:53:24

标签: swift xcode firebase firebase-dynamic-links

过去,动态链接在实际设备和模拟器上都可以正常工作。当我单击模拟器中的链接(或将其粘贴到safari中)时,我将重定向到“ .page.link”站点,其上显示“打开”-单击“打开”将完美打开该应用程序。但是,如果我在实际设备上重复相同的步骤,则会重定向到支持URL,并且什么也不会发生(即使将应用安装在手机上,应用也无法打开)。

这是我显示网址的代码

if let uid = Auth.auth().currentUser?.uid {
            guard let link = URL(string: "https://www.testapp.com/uid=" + uid) else {
                return
            }
            let dynamicLinksDomain = "testapp.page.link"
            let linkBuilder = DynamicLinkComponents(link: link, domain: dynamicLinksDomain)
            linkBuilder.iOSParameters = DynamicLinkIOSParameters(bundleID: "com.burgertralla.theGreat")
            linkBuilder.shorten { (url, _, _) in
                if let url = url {
                  self.shareTopLabel.text = url.absoluteString
                }
            }
        }

这是我的AppDelegate:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        if let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url) {
            self.handleIncomingDynamicLink(dynamicLink: dynamicLink)
            return true
        }
        return false
    }

    func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
        if let incomingUrl = userActivity.webpageURL {
            let linkHandled = DynamicLinks.dynamicLinks().handleUniversalLink(incomingUrl, completion: { (dynamicLink, _) in
                if let dynamicLink = dynamicLink, let _ = dynamicLink.url {
                    self.handleIncomingDynamicLink(dynamicLink: dynamicLink)
                }
            })

            if linkHandled {
                return linkHandled
            }
        }
        return false
    }

    func handleIncomingDynamicLink(dynamicLink: DynamicLink) {
        guard let pathComponents = dynamicLink.url?.pathComponents else {
            return
        }
        for pathComponent in pathComponents {
            if pathComponent.contains("uid=") {
                let uid = pathComponent.drop(prefix: "uid=")
                Database.database().reference(withPath: "profile/" + uid).observeSingleEvent(of: .value) { (snapshot) in
                    if snapshot.exists(), var data = snapshot.value as? [String: Any] {
                        data["uid"] = snapshot.key
                        let userProfileVC = UIStoryboard(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "UserProfileViewController") as! UserProfileViewController
                        if let tabBarVc = self.window?.rootViewController as? UITabBarController {
                            tabBarVc.selectedIndex = 1
                            if let discoveryVC = tabBarVc.viewControllers?[1] as? UINavigationController {
                                userProfileVC.selectedUser = data
                                discoveryVC.pushViewController(userProfileVC, animated: true)
                            }
                        }
                    }
                }
            }
        }
    }

有人对这里发生的事情有任何线索吗?

感谢帮助人员:)

编辑:它可以在装有Chrome的iPhone上运行,但不适用于Safari。我不知道为什么...

0 个答案:

没有答案