I want to adopt the state restoration in my app. I've opted out of using SceneDelegate because my app is not supposed to be running in multiple windows.

So I've implemented the necessary methods in my AppDelegate

func application(_ application: UIApplication, shouldSaveSecureApplicationState coder: NSCoder) -> Bool {
    return true
}

func application(_ application: UIApplication, shouldRestoreSecureApplicationState coder: NSCoder) -> Bool {
    return true
}

But every time I quit the app I get this message in the debugger

No windows have a root view controller, cannot save application state

I setup my window programmatically at the launch of app like this

func configureWindow() {
        let window = UIWindow(frame: UIScreen.main.bounds)
        
        let launchViewController = Storyboard.launch.instantiate() as LaunchViewController
        launchViewController.viewModel = LaunchViewModel(context: context)
        window.rootViewController = RootNavigationController(rootViewController: launchViewController)
        window.makeKeyAndVisible()
        
        self.window = window
    }

So I don't see how is it possible that at the time the app gets killed it has no rootViewController.

This definitely seems like a bug to me, but has anyone encountered such issue?

1

There are 1 best solutions below

1
On

I've opted out of using SceneDelegate because my app is not supposed to be running in multiple windows.

Check this answer, it links to the article, that says

The best way to implement UI state restoration is to make your app scene-based