In SwiftUI iOS 16+ app I have a deep link logic in the SceneDelegate.
According to the URL I can switch on it and navigate or present the ViewController that I want to show either inserting it to a NavigationController or presenting a Modal by finding the top ViewController with this logic :
extension UIApplication {
class func getTopViewController(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
if let nav = base as? UINavigationController {
return getTopViewController(base: nav.visibleViewController)
} else if let tab = base as? UITabBarController, let selected = tab.selectedViewController {
return getTopViewController(base: selected)
} else if let presented = base?.presentedViewController {
return getTopViewController(base: presented)
}
return base
}
}
In a SwiftUI app where I don’t have a top ViewController how do I decide if to append the current view from the deep link logic to a NavigationStack path or to present it Modally?
Thanks for the help.