SwiftUI .onContinueUserActivity(NSUserActivityTypeBrowsingWeb) doesn't seem to work

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?

Answered by DTS Engineer in 801037022

@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.

@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.

@DTS Engineer That modifier unfortunately doesn't allow accessing the referrerUrl which is what we need.

Hi @leonardo_dasilva,

This behavior is not currently supported in the SwiftUI lifecycle. Please see the following forums post for more information:

SwiftUI onOpenURL lacks referrerURL and annotation present in NSUserActivity https://forums.developer.apple.com/forums/thread/755902?answerId=788545022#788545022

Cheers,

Paris X Pinkney |  WWDR | DTS Engineer

SwiftUI .onContinueUserActivity(NSUserActivityTypeBrowsingWeb) doesn't seem to work
 
 
Q