请帮我解决这个问题。我已经按照https://www.raywenderlich.com/128948/universal-links-make-connection实现了通用链接,而我遇到的问题是,当我点击链接时,我被重定向到网络浏览器而不是应用程序。在safari浏览器中,当我向下滚动页面时,我得到一个也有OPEN按钮的横幅。点击它,我的应用程序打开,根据逻辑打开特定的视图控制器。那么为什么它首先在浏览器中打开?如果已安装应用,则应直接在应用中打开,而不是使用网络浏览器。
以下是我的应用代表中的方法:
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)
}
}
答案 0 :(得分:0)
听起来你无意中停用了Universal Links。如果在打开通用链接后点击屏幕右上角的旁路链接,通常会发生这种情况。有关如何撤消流程的详细信息,请参阅this answer。