views:

269

answers:

1

I'm using - (void)applicationWillTerminate:(NSNotification *)notification to save data when my game exits, then loading it if the user presses the load button next time around. The saving and loading work fine, but I've noticed there is some lag between when I press the home button and when the data gets saved. Whenever I exit, relaunch and load, the game's timer has kept ticking and states were changing before applicationWillTerminate gets called; e.g. game objects in motion are loaded at different locations then what I last saw pressing the home button. Interestingly enough, if I press the home button rapidly.. it appears to quit the quitting of the application, and the music controls pop up. However, if I quit in this fashion whenever I load the data again, the timer did not continue -- game objects did not keep moving with their velocities. Is there a way around this?

A: 

Have you looked at UIApplicationWillResignActiveNotification? Something like the following at load / init time in your 'main controller' or UIApplication subclass:

[[NSNotificationCenter defaultCenter] addObserver:self /* or whatever */ selector:@selector(applicationWillTerminate:) name:UIApplicationWillResignActiveNotification object:NULL];
johne