I am using Swift 2 and Xcode 7 for iOS 9.2
My, basically finished, game-app creates a complex view (SceneKit
+ SpriteKit
+ random variables + game progress). When I switch to the Menu and back, everything stays the same (just switching views or scenes). However, when the application is closed, it restarts with the main.storyboard's entry-point and my data is gone.
The app should open the same state it was closed on.
I already tried archiving relevant data with NSCoding
to save/load the scene- but it always ends up in a weird or non-informative Error or white screen which do not help me with finding my mistake at all. I do not know at all, where the error is; no useful information is provided from Xcode.
But even if it worked, it would not solve my entry-point problem.
Is there a simple way to just restart from the last state+view that my app had?
Do I need NSCoding
or NSUserDefaults
for this?
You should use State Restoration.
It's designed for that exact purpose to return an app to its previous state, and can be used to restore the state of your app, including its SpriteKit scene.
You'll find further details in the App Programming Guide for iOS documentation, under Preserving Your App’s Visual Appearance Across Launches.