This may be a really basic question, but I have made a simple game in which the user avoids oncoming obstacles. When I press the home button my app is still running in the background, and because of this the app music continues playing and all my NSTIMERS continue which eventually causes the game character to hits an obstacle).
Can show me how to pause the game when I press the home button or switch to another app (game is in the background state), then resume when the app is in the foreground again?
Use this code:
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(pauseGameSoUserDoesNotDieForNoReason:)
name: UIApplicationDidEnterBackgroundNotification
object: nil];
Put it in the setup method of .m file that contains your timers and the method.
Put this in the .m file as well
-(void)pauseGameSoUserDoesNotDieForNoReason:(NSNotification*)theNotification{
}
This last method:
-(void)pauseGameSoUserDoesNotDieForNoReason:(NSNotification*)theNotification
Is where you put your pausing code.
This code can be placed in several .m files.