Skip to content

Instantly share code, notes, and snippets.

@shahdhiren
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shahdhiren/00d2041c971a55d548f0 to your computer and use it in GitHub Desktop.
Save shahdhiren/00d2041c971a55d548f0 to your computer and use it in GitHub Desktop.
How to prevent the Screen from Locking
By default, iOS will lock the screen and disable the touch sensor if there are no touch events for a specified period of time. Depending on your application, there may be times that you need to keep the screen from locking. For example, if your application is primarily accelerometer driven (such as a game), there may be minimal touch events to keep the screen from reseting its internal timer.
You can disable the idle timer through the idleTimerDisabled property of the shared UIApplication object:
// Disable the idle timer
[[UIApplication sharedApplication] setIdleTimerDisabled: YES];
// Or for those who prefer dot syntax:
[UIApplication sharedApplication].idleTimerDisabled = YES;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment