I have a Siri Intent that displays a simple UI. When the user taps on it, the app is launched.
When the app is in the background, I use the following code
in the Scene Delegate to capture what the user did and take the user to the right view. It works as expected.
However, I can't figure out what to do when the app is launched when it is NOT in the background.
My understanding is that UIScene.ConnectionOptions should be populated, but it's empty.
In the SceneDelegate
I also tried the following methods but they never get called:
Also tried this in the AppDelegate:
When the app is in the background, I use the following code
in the Scene Delegate to capture what the user did and take the user to the right view. It works as expected.
Code Block func scene(_ scene: UIScene, continue userActivity: NSUserActivity) { print("CONTINUE USER ACTIVITY") guard let intent = userActivity.interaction?.intent as? WasteWizardIntent else { print("AppDelegate: WasteWizardIntent - FALSE") //return false return } print("AppDelegate: WasteWizardIntent - TRUE") print(intent) appState.selectedTab = .wastewizard appState.deepLinkActionSheet = true appState.deepLinkString = intent.garbage! //contentView.wasteWizard.viewModel.goToWasteItem(for: intent.garbage!) }
However, I can't figure out what to do when the app is launched when it is NOT in the background.
My understanding is that UIScene.ConnectionOptions should be populated, but it's empty.
In the SceneDelegate
Code Block scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions)
method. When I put a breakpoint, the userActvity, intent and handoffUserActivityType are all nil.Code Block if let windowScene = scene as? UIWindowScene { let window = UIWindow(windowScene: windowScene) window.rootViewController = UIHostingController(rootView: contentView) RootAlerter.shared.rootViewController = window.rootViewController self.window = window window.makeKeyAndVisible() let userActivity = connectionOptions.userActivities let string = connectionOptions.handoffUserActivityType let intent = userActivity?.interaction?.intent as? WasteWizardIntent print("handoff type \(connectionOptions.handoffUserActivityType)") }
I also tried the following methods but they never get called:
Code Block func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) func scene(_ scene: UIScene, didUpdate userActivity: NSUserActivity) func scene(_ scene: UIScene, willContinueUserActivityWithType userActivityType: String)
Also tried this in the AppDelegate:
Code Block private func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool