Where is UIApplication.OpenURLOptionsKey in SwiftUI app lifecycle?

Using the UIKit application lifecycle and this delegate method

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool

I can access options associated with a user tapping on a custom URL. In particular I can access the bundle ID of another app of mine that triggered a custom URL to launch the target app via this property:

https://developer.apple.com/documentation/uikit/uiapplication/openurloptionskey/1623128-sourceapplication

When I output the "options" parameter after triggering I can see the bundle ID clearly for UIApplicationOpenURLOptionsSourceApplicationKey:

options: [__C.UIApplicationOpenURLOptionsKey(_rawValue: UIApplicationOpenURLOptionsSourceApplicationKey): COM.MYDOMAIN.TestURL2, __C.UIApplicationOpenURLOptionsKey(_rawValue: UIApplicationOpenURLOptionsOpenInPlaceKey): 0]

However, when using the SwiftUI application lifecycle the above app delegate function is not called in favor of the SwiftUI view extension:

onOpenURL(perform action: @escaping (URL) -> ()) -> some View

This has only the custom URL and no other options and thus I cannot find a way to find out which of my other apps triggered the target app via a custom URL.

Does anyone know if there's a way to get this information in an app that uses the SwiftUI app lifecycle or is it not available except in an app that uses the UIKit application lifecycle?

Answered by Vision Pro Engineer in 791167022

Hi @Purseus ,

With SwiftUI, only onOpenURL will be called, even if you do have an app delegate adaptor. You will not be able to get that information, you're correct.

Please file a feedback report about this at https://feedbackassistant.apple.com , I've seen many people asking for this behavior on here and the more people that request it, the better. Paste the FB number here after. Thanks!

For now this information is not available with onOpenURL, but one way you could try is to use the UIApplicationDelegateAdaptor https://developer.apple.com/documentation/swiftui/uiapplicationdelegateadaptor to continue receive the same delegate function that get the URL option there, then pass it into your view model.

Hi!

Thank you for the info, but unfortunately the UIApplicationDelegate protocol method that's used for this purpose this in an app with the UIKit lifecycle ...

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool

.. does not appear to be called in an app with the SwiftUI application lifecycle when instantiated via the UIApplicationDelegateAdaptor property wrapper.

Is this data not yet available in an app with the SwiftUI application lifecycle?

(Also tested with iOS 18 beta and Xcode 16 beta. Same result. That delegate function doesn't appear to be called even with UIApplicationDelegateAdaptor.)

Accepted Answer

Hi @Purseus ,

With SwiftUI, only onOpenURL will be called, even if you do have an app delegate adaptor. You will not be able to get that information, you're correct.

Please file a feedback report about this at https://feedbackassistant.apple.com , I've seen many people asking for this behavior on here and the more people that request it, the better. Paste the FB number here after. Thanks!

Hi,

Thank you for the information! I have submitted a feedback report.

The FB number is FB13943979

Thanks!

Where is UIApplication.OpenURLOptionsKey in SwiftUI app lifecycle?
 
 
Q