I have my app set-up to handle Universal links. We handle the retrieval of the URL, and the navigation given the URL inside of this function:
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
guard NSUserActivityTypeBrowsingWeb == userActivity.activityType, let url = userActivity.webpageURL else {
return false
}
// Do navigation to correct page based on URL
return true
}
This works perfectly for us when our app was previous running in the background, and a universal link is tapped.
However, when I kill the app completely and click on a universal link, this function doesn't appear to be running and so it doesn't handle the universal link at all, it just brings the user to the home tab.
I've tried grabbing the URL in application(didFinishLaunchingWithOptions:)
and application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:])
but neither of those seem to get called as well.
Does anyone have any ideas on this?
Thank you!
Swift 5 IOS 14 When app is terminated use
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Get URL components from the incoming user activity.
guard let userActivity = connectionOptions.userActivities.first,
userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let incomingURL = userActivity.webpageURL
else { return }
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
LinkHandler.sharedInstance.handleLink(url: incomingURL)
}
guard let _ = (scene as? UIWindowScene) else { return }
}
On application(didFinishLaunchingWithOptions:)
url is inside an options.
Please test it again.
Apple docs: launchOptions A dictionary indicating the reason the app was launched (if any). The contents of this dictionary may be empty in situations where the user launched the app directly. For information about the possible keys in this dictionary and how to handle them, see Launch Options Keys.
https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622921-application
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With