I have created a game... however when the device is turned off I need the game to pause... is there an action like viewdi开发者_StackOverflowdload for when the device is turned off? thankyou
If by "off" you mean "sleep", there are two ways:
Implement these in your app delegate:
- (void)applicationWillResignActive:(UIApplication *)application
{
// do sleep stuff
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// do wake stuff
}
Or register for these notifications:
[[NSNotificationCenter defaultCenter] addObserver:thingThatCares
selector:@selector(whatToDoOnSleep:)
name:UIApplicationWillResignActiveNotification
object:[UIApplication sharedApplication]];
[[NSNotificationCenter defaultCenter] addObserver:thingThatCares
selector:@selector(whatToDoOnWake:)
name:UIApplicationDidBecomeActiveNotification
object:[UIApplication sharedApplication]];
I would use the app Delegate method:
- (void)applicationWillTerminate:(UIApplication *)application
to pause your game.
精彩评论