State restoration in iOS 14

685 Views Asked by At

I am trying to use state restoration in my app, but for some reason I cannot get it to work. I have the restoration ID set in all view controllers, navigation controllers, and tab bar controllers. I have opted in using the following functions in AppDelegate

func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        return true
    }
    func application(_ application: UIApplication, shouldRestoreSecureApplicationState coder: NSCoder) -> Bool {
        return true
    }
    func application(_ application: UIApplication, shouldSaveSecureApplicationState coder: NSCoder) -> Bool {
        return true
    }

After killing the app on simulator and on a device, it does not restore any states. I am not receiving any warnings, am I missing something?

1

There are 1 best solutions below

0
On

In order to test state restoration on the simulator you need to start your app, go back to the home screen and then press stop in Xcode with the app now in the background. Then when you launch it again, its state will get restored.