开发者

Action executed when iphone is turned off

开发者 https://www.devze.com 2023-02-09 00:04 出处:网络
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? thankyouIf by \"of

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

精彩评论

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