The document discusses URL routing in a SwiftUI app. It explains that URL routing can now be handled in the SceneDelegate using the scene(_:openURLContexts:) method rather than the AppDelegate. It provides an example of parsing the URL and programmatically navigating to the destination view controller. It also discusses using the NavigatorInsertionView to programmatically push views onto the navigation stack.
8. Route to Goal Screen from Current Screen
- UIApplication.keyWindow Deprecated
9. Route to Goal Screen from Current Screen
- SceneDelegate.window
import UIKit
import SwiftUI
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
…
New
10. Route to Goal Screen from Current Screen
- UIWindow SwiftUI View
- … ViewController ?
11. Route to Goal Screen from Current Screen
- UIWindow SwiftUI View
- … ViewController ?
SwiftUI .sheet ViewController present
12. Route to Goal Screen from Current Screen
- UIWindow SwiftUI View
- … ViewController ?
UIWindow
UIHostingController(VC)
SwiftUI .sheet ViewController presentSwiftUI
13. Route to Goal Screen from Current Screen
- UIWindow SwiftUI View
- … ViewController ?
UIWindow
SwiftUI .sheet ViewController present
.sheet
.presentUIHostingController(VC)
SwiftUI
UIHostingController(VC)
SwiftUI
14. Route to Goal Screen from Current Screen
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
let url = URLContexts.first?.url
let distinationView = parseURLToDistination(url: url)
var currentTopVC = window?.rootViewController
while true {
if let presentedVC = currentTopVC?.presentedViewController {
currentTopVC = presentedVC
} else {
break
}
}
currentTopVC?.present(UIHostingController(rootView: distinationView), …
}
15. Route to Goal Screen from Current Screen
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
let url = URLContexts.first?.url
let distinationView = parseURLToDistination(url: url)
var currentTopVC = window?.rootViewController
while true {
if let presentedVC = currentTopVC?.presentedViewController {
currentTopVC = presentedVC
} else {
break
}
}
currentTopVC?.present(UIHostingController(rootView: distinationView), …
}
url
url View
VC
UIHostingController View
VC