Please help me in this issue. I have implemented universal links by following https://www.raywenderlich.com/128948/universal-links-make-connection and the problem I am getting is that when I click on a link, I am redirected to web browser instead of app. And in safari browser, when I scroll down the page, I am getting a banner which has OPEN button also. By clicking it, my app opens and the specific view controller according to the logic opens. So why it is opening in browser at first? If app is installed, it should directly open in app instead of web browser.
Following are the methods in my app delegates:
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)
}
}
It sounds like you inadvertently deactivated Universal Links. This usually happens if you tap the bypass link in the top right corner of the screen after opening a Universal Link. See this answer for details on how to reverse the process.