Method to save application state just before quit

I am using the user preferences to save the state of my game so that when a user goes away and comes back, it comes back at the same place they left. However, I am saving to this every turn. Is there a better way of doing this. Putting it in the applicationWillTerminate method maybe? If so, I'm not quite sure how to accomplish it there. Can anyone give any advice on this?

Thanks.

Mac Pro - 3 gig RAM, 3 HDs, Mac OS X (10.5.5)

Posted on Oct 16, 2008 7:06 PM

Reply
5 replies

Oct 16, 2008 7:10 PM in response to Michael Reiland

applicationWillTerminate is the proper place to save your game. What is the difficulty in performing the action there? You just need to save the game as you would from the other location in your application from which you are performing the action. You may need to store a reference to the controller (or other class) in the application delegate to be able to perform the save action.

Oct 17, 2008 11:41 PM in response to Michael Reiland

I made it work by setting up the MainViewController as a class and a variable in the Application Delegate. Then once the MainViewController was established, I called a method I put into the Application Delegate to set that variable to "self" (meaning MainViewController instance). Finally, in the applicationWillTerminate method of the Application Delegate, I used that variable to call the save method in the MainViewController.

Perhaps this is difficult to follow without seeing the code, but does this sound overly complicated, or about right?

Thanks.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Method to save application state just before quit

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.