简体   繁体   中英

State restoration in iOS 14

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM