0
votes

I want some advice on how to properly take on implementing state preservation and restoration for an app that has been build already, having lot of view controllers and complex hierarchy.

What are the things to be kept in mind when trying to preserve state for an app that is running for a while already?

EDIT:

I want to get clarified or possibly get a solution to a problem that I am facing in terms of restoring state goes. I successfully restore app' state on launch. I restore a view controller and other view controllers in hierarchy. Now when I push another view controller and sequence of other view controllers to nav. stack, at a particular view controller, for some reason the app crashes due to an exception. So when I open the app back, it still restores the first view controller's state that was preserved when pressing home button.

Specifically I want to know if there is any way to discard app state info. when app terminates due to uncaught exception? I know that the state will be discarded if user manually force kills app, or state restoration fails, or the app terminates at launch. Is there a way to catch a termination and configure app state accordingly? Suggestions would be great. Thanks.

1
Too broad. An app is an app. State restoration is state restoration. If you want to add state restoration, add it. It's pretty simple (though of course you will have a lot of work to do, since you must deal with every view controller individually). What specific problem have you experienced?matt
From my understanding, state restoration should be done as we move along building the app. Like, planning ahead and start implementing. I want to know if there will be any specific difficulties doing restoration after an app is finished. Just want to plan ahead instead of getting stuck and involving too much time.badhanganesh
"I want to know if there will be any specific difficulties doing restoration after an app is finished. Just want to plan ahead instead of getting stuck and involving too much time." Too broad! How can we know if you will have specific difficulties? If you have a specific problem, come back and ask about it. As it stands, this is just not an appropriate question for Stack Overflow. We don't have a crystal ball. Dig in and see what happens.matt
You want a specific recommendation for when you're worried about getting stuck and involving too much time? Use git and work on a branch. There. Now get to work! :)matt

1 Answers

1
votes

From my understanding, state restoration should be done as we move along building the app

No, I don't think that's right at all. The whole beauty of the built-in state saving-and-restoration mechanism is that it can be patched right onto the working app, one view controller at a time. You don't even have to complete it for the whole app before testing; on the contrary, another beauty of the mechanism is that it works for just the subset of the view controller hierarchy for which it is in fact implemented, with no harm done to the rest of the app. So just start at the top of the view controller hierarchy and start implementing it.