4 Replies
      Latest reply: Dec 1, 2016 1:03 AM by eskimo RSS
      3DTOPO Level 1 Level 1 (0 points)

        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?

        • Re: Testing App State Saving/Restoration without Xcode Connected?
          eskimo Apple Staff Apple Staff (6,270 points)

          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"

            • Re: Testing App State Saving/Restoration without Xcode Connected?
              3DTOPO Level 1 Level 1 (0 points)

              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.

                • Re: Testing App State Saving/Restoration without Xcode Connected?
                  KMT Level 8 Level 8 (7,350 points)

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

                  • Re: Testing App State Saving/Restoration without Xcode Connected?
                    eskimo Apple Staff Apple Staff (6,270 points)

                    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"