HI,
I'm trying to deeplink from my widget to a view in my app. I'm using the "SwiftUI app lifecycle".
This the code I'm currently using:
var body: some Scene {
        WindowGroup {
            RootView()
                .onContinueUserActivity("NextDeparturesWidgetConfigurationIntent") { userActivity in
                    guard let configuration: NextDeparturesWidgetConfigurationIntent = userActivity
                        .widgetConfigurationIntent(),
                        let stationEntity = configuration.stationEntity else { return }
                    NotificationCenter.default.post(name: .onOpenStation, object: stationEntity.id)
                }
        }
    }
It is working fine when the app is already running (in the background).
However when the app is "cold starting" (ie. not in memory) onContinueUserActivity is never called.
I tried adding a UIApplicationDelegateAdaptor:
    func application(
        _ application: UIApplication,
        configurationForConnecting connectingSceneSession: UISceneSession,
        options: UIScene.ConnectionOptions
    ) -> UISceneConfiguration {
        if let userActivity = options.userActivities.first {
            let configuration: NextDeparturesWidgetConfigurationIntent? = userActivity.widgetConfigurationIntent()
            // casting fails
        }
        return UISceneConfiguration(
            name: nil,
            sessionRole: connectingSceneSession.role
        )
    }
I can see that the activity is received but it is never casted to NextDeparturesWidgetConfigurationIntent.
What am I missing ?
Hi,
In your SwiftUI View
.onOpenURL(perform: { (url) in
Should be called in response to the
.widgetURL(entry.character.url)
set on your Widget's SwiftUI view.
You can see the Emoji Rangers sample project for additional information
Rico WWDR - DTS - Software Engineer