开发者

Action executed when iphone is turned off

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜