How can we check if the iphone has gone into a standby mode and returns from that mode programmaticlly? I am using this to force it not to sleep during the game:
application.idleTimerDisabled = YES;
But if the user uses the sleep button it messes up开发者_JS百科 with my game state in my code. Any help would be appreciated, thanks in advance.
Your application will be told that the device is locking. In your applicationDelegate you can implement the
- (void)applicationWillResignActive:(UIApplication *)application
and
- (void)applicationDidBecomeActive:(UIApplication *)application
methods, to receive the notifications.
When your application transitions to inactive no events will be dispatched for it so you will be unable to do anything meaningful. Save your state as the device goes to sleep, and restore it on wake.
The app delegate will get a applicationWillResignActive:
message before the device goes to sleep.
精彩评论