ioscocoa-touchuikit-state-preservation

iOS State Restoration


I am fairly new to iOS development and I am trying to understand the State Restoration API. Without implementing the APIs in my application, when the application is exited and resumed it does restore the state of the application to the way it was before the user exited. If this is not State Restoration, then what mechanism is this? And how is it different than State Restoration? Why should I implement state restoration when the default mechanism seems to do what I need.

I'm sure that I'm just not understanding something, but I don't know what it is.


Solution

  • If you open the multitasking tray and force quit your app, if you don't implement any means to restore state, the app will launch and will run through its UIWindow heirarchy like normal via applicationDidFinishLaunching . State Restoration just provides a simple way to archive objects that comply with NSCoding, so if you decide to make your view heirarchy compliant you can just pass in your Navigation stack, for instance. THen when the proper methods get called upon launch, if the app is not coming out of suspension but is being launched cold, it will use those archived objects to repopulate the heirarchy.

    It's not just implementing a couple of methods though, none of the state restoration is handled for you for free. I just believe it handles where the archiving occurs and what the filenames are. It's up to you to decide what gets archived, and what to do with the objects when you unarchive them.