Testing App State Saving/Restoration without Xcode Connected?

I am saving and restoring my app's state by opting in (in the AppDelegate):

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

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


This works when I kill the app with the Xcode stop execution button after the app has been backgrounded.


But when I try to kill the backgrounded app (by double tapping the home button and swiping the app up off the screen), then the app state is not restored when relaunched. IIRC this used to work.


How can I quit out of the app without Xcode so that it will restore its' state? Or is it now only possible to test it using Xcode?

But when I try to kill the backgrounded app (by double tapping the home button and swiping the app up off the screen), then the app state is not restored when relaunched.

ISTR that removing the app from the multitasking UI specifically disables state restoration, on the grounds that the user only does this when there’s something wrong with the app and thus it’s better to start from a clean slate.

How can I quit out of the app without Xcode so that it will restore its' state?

Have you tried calling

exit
? It’s definitely not OK to do this in production code (see QA1561) but it’s fine to use while testing.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thank you for confirming that is the expected behavior.


So, I take it there is no way to exit the app and save the state other than calling exit? I wanted to provide instructions to beta testers how to test the app's restoration, but adding a 'exit' button is less than ideal.

Try doing an ad-hoc install....they sometimes better replicate a store install, as an example, vs. debug when Xcode connected.

I wanted to provide instructions to beta testers how to test the app's restoration, but adding a 'exit' button is less than ideal.

Quite. I misinterpreted what you meant by “testing”. I assumed you were talking about in-house testing but you’re actually talking about beta testing. Having an Exit button is definitely not appropriate for beta testers.

In terms of purely user-level options, the ones that spring to mind are:

  • Restart the phone

  • Update the app

  • Run a bunch of resource hungry apps, which results in the system kicking your app out of memory

At a code level you could do the

exit
when the app is in the background, perhaps using some statistical model so that sometimes it exists and sometimes it does. However, there’s two risks with adding code like this:
  • You have to make sure that the code gets disabled in your production build.

  • It introduces a behaviour difference between your beta test build and production build, which is something you generally want to avoid.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Testing App State Saving/Restoration without Xcode Connected?
 
 
Q