we try to reset the current View to Root if App will enter Foreground.
How can we do that in SwiftUI?
func sceneWillEnterForeground(_ scene: UIScene) {
There is no "go back" but the possible approach is to recreate root view controller, by moving "by default" generated content creation into other delegate method as below...
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
self.window = window
}
}
func sceneWillEnterForeground(_ scene: UIScene) {
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
let contentView = RootView().environment(\.managedObjectContext, context)
let singleOrder = SingleOrder()
window?.rootViewController = UIHostingController(rootView: contentView.environmentObject(singleOrder))
window?.makeKeyAndVisible()
}