Question

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 with my game state in my code. Any help would be appreciated, thanks in advance.

Was it helpful?

Solution

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.

OTHER TIPS

The app delegate will get a applicationWillResignActive: message before the device goes to sleep.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top