We need to read the value for userActivity.referrerUrl
when the app is accessed through a Universal Link, which when using the UIKit lifecycle we can easily do by implementing the method scene(_: UIScene, continue: NSUserActivity)
in SceneDelegate
and filtering for activity type of NSUserActivityTypeBrowsingWeb
.
When the app uses the SwiftUI lifecycle that method doesn't get called, even though the app is correctly configured to use AppDelegate and SceneDelegate (through the @UIApplicationDelegateAdaptor
wrapper). I can confirm that the setup is correct because the method scene(_: UIScene, willConnectTo: UISceneSession, options: UIScene.ConnectionOptions)
in SceneDelegate
is called on app launch.
The obvious SwiftUI way of achieving the same would be by using the .onContinueUserActivity(NSUserActivityTypeBrowsingWeb)
modifier, but that doesn't work. Is this a bug?
@leonardo_dasilva SwiftUI passes a Universal Link to your app directly as a URL. To receive a Universal Link, use the onOpenURL(perform:) modifier instead.