'iOS Swift 5 Deeplink userActivity Method not called
In Swift 4 it's working fine in all device and iOS versions.
After upgrading to swift 5 deeplink open the app, But userActivity method is not called.
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL
else { return false }
print(url)
return true
}
Our App support iOS 10 and above.
Solution 1:[1]
restorationHandler Callback type has been changed from [Any] to [UIUserActivityRestoring] then it's working fine for me.
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL
else { return false }
print(url)
return true
}
Solution 2:[2]
if you set the initial viewController via SceneDelegate. You need to add this to SceneDelegate
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL else {
return
}
print(url)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Oguzhan Karakus |
