首页 文章

Universal Links在Safari浏览器上显示 Banner

提问于
浏览
0

请帮我解决这个问题 . 我已经按照https://www.raywenderlich.com/128948/universal-links-make-connection实现了通用链接,我得到的问题是,当我点击链接时,我被重定向到Web浏览器而不是应用程序 . 在safari浏览器中,当我向下滚动页面时,我得到一个也有OPEN按钮的 Banner . 点击它,我的应用程序打开,根据逻辑打开特定的视图控制器 . 那么为什么它首先在浏览器中打开?如果安装了应用程序,它应该直接在应用程序而不是Web浏览器中打开 .

以下是我的应用代表中的方法:

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {

        if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
            guard let url = userActivity.webpageURL else {
                return false
            }
            openViewController(url)
        }
        return true
    }

func openViewController(url: NSURL) {
        let components = NSURLComponents(URL: url, resolvingAgainstBaseURL: true)
        print(components)
        print(url.absoluteString)
        if url.host == "refit.co" && (url.pathComponents![2] == "supplements" || url.pathComponents![2] == "equipments") {
            print("This is the supplements/equipments universal link")
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyboard.instantiateViewControllerWithIdentifier("Home")
            let navController = self.window?.rootViewController as? UINavigationController
            navController?.pushViewController(vc, animated: false)
            let vc2 = storyboard.instantiateViewControllerWithIdentifier("SupplementDetail") as? VCSupplementDetail
            vc2?.itemID = getID(url.query!)
            vc2?.screenName = url.pathComponents![2] == "supplements" ? "Supplements" : "Equipments"
            navController?.pushViewController(vc2!, animated: true)
            print("Query: \(url.query)")
        } else {
            print("This is the url: \(url)")
            print(url.host)
            print(url.path)
            print(url.query)
            print(url.pathComponents)
        }
    }

1 回答

  • 0

    听起来你无意中停用了Universal Links . 如果在打开通用链接后点击屏幕右上角的旁路链接,通常会发生这种情况 . 有关如何撤消该过程的详细信息,请参阅this answer .

相关问题