I am working with universal link to open iOS application and on this basis of link data I have to open viewcontroller in my iOS application.
I am using Xcode 10.0. And running application on iOS 12.0 (iPhone 7 Plus).
This is my universal link: https://en5vz.app.goo.gl/kjvaHzXrLMNBEDtG7
When I tap on this link then application is launched but method given below is not being called:
private func application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
print("\(#function) ---- \(userActivity.webpageURL)")
if #available(iOS 11.0, *) {
print("\(#function) ---- \(userActivity.referrerURL)")
} else {
// Fallback on earlier versions
}
if let incominURL = userActivity.webpageURL{
let linkHandled = DynamicLinks.dynamicLinks()?.handleUniversalLink(incominURL, completion: { (dynamiclink, error) in
if let dynamiclink = dynamiclink, let _ = dynamiclink.url{
self.handleIncomingDynamicLink(dynamiclink: dynamiclink)
}
})
return linkHandled!
}
return false
}
This is an old question, but for anyone looking, the missing component here is the app-site-association
file: https://developer.apple.com/documentation/uikit/core_app/allowing_apps_and_websites_to_link_to_your_content/enabling_universal_links
Take the following steps to associate your app and website for universal links:
- Add the Associated Domains Entitlement to your app. Include all domains your app will support using the applinks service prefix. See Add the Associated Domains Entitlement.
- Add an Apple App Site Association file to your website. See Add the Apple App Site Association File.
- Add the applinks key to the Apple App Site Association file. Specify the sections of your website each of your apps will handle.
You've done step 1 (and step 0, which is setting up the code in your app), but steps 2 and 3 are missing.
I hope this help those in future facing this. I had the same problem where I could open the link to my website using ios App but could not log. I found out later that it was the @escaping [Any]? part that caused it. I changed my code to this instead: @escaping ([UIUserActivityRestoring]?) and it logged to the Xcode console.
func application(_ application: UIApplication, continue userActivity:
NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
print("Continue User Activity called: ")
if userActivity.activityType == NSUserActivityTypeBrowsingWeb {
let url = userActivity.webpageURL!
print(url.absoluteString)
//handle url and open whatever page you want to open.
}
return true
}
For deep linking I would expect it to call the open url function:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool
Does that not work for you?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.