ARTICLE AD BOX
I’m building an iOS app in Swift with deep links that open specific screens/modules.
Problem:
When the app is already running in foreground, clicking a deep link works fine — the screen opens and the tab bar + navigation bar are visible.
But when the app is in the background or killed, clicking the deep link opens the screen, but the tab bar and navigation bar are missing.
What I have:
SceneDelegate:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let windowScene = scene as? UIWindowScene else { return } window = UIWindow(windowScene: windowScene) window?.makeKeyAndVisible() if let userActivity = connectionOptions.userActivities .first(where: { $0.activityType == NSUserActivityTypeBrowsingWeb }) { DispatchQueue.main.async { DeepLinkManager.shared.handle(userActivity: userActivity) } } }DeepLinkManager routing code:
private func routeToViewController(viewController: UIViewController) { guard let windowScene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene, let window = windowScene.windows.first(where: { $0.isKeyWindow }), let rootVC = window.rootViewController else { return } if let tabBar = rootVC as? UITabBarController, let nav = tabBar.selectedViewController as? UINavigationController { let dashboardVC = nav.viewControllers.first { String(describing: type(of: $0)) == "DashboardViewController" } ?? nav.viewControllers.first nav.setViewControllers([dashboardVC, viewController].compactMap { $0 }, animated: true) tabBar.selectedIndex = tabBar.viewControllers?.firstIndex(of: nav) ?? 0 return } let navVC = UINavigationController(rootViewController: viewController) navVC.modalPresentationStyle = .fullScreen rootVC.present(navVC, animated: true) }Observation:
Works fine if app is foregrounded.
On background/cold start, the deep link screen shows, but tab bar and navigation bar are missing.
What I need help with:
How can I ensure that:
Deep links always open on the correct tab/navigation stack.
Tab bar and navigation bar are visible even when the app is backgrounded or killed.
Back navigation goes correctly to the Dashboard.
