How to Prevent the iPhone from Sleeping

Dec 17, 2009   //   by Derek van Vliet   //   Development  //  No Comments


Left idle, the iPhone goes into sleep mode after about a minute. This narcoleptic behaviour saves on battery life, but there are situations where you would not want the device to go to sleep. For instance, in the middle of a multiplayer game that is turn-based, such as chess. You could wait for longer than a minute for your opponent to make make their move and you wouldn’t want to miss it when they did.

To keep the iPhone awake and alert, simply run the following line of code:

[UIApplication sharedApplication].idleTimerDisabled = YES;

Do use this tip sparingly though. The iPhone’s power is unmatched, to be sure, but unfortunately it is not unlimited.

Leave a comment

Our Games