How to Keep the Screen from Locking

Mon, Jul 25

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;


Great! It does not help to prevent the App to enter the Deep Sleep mode when the user hit the top button of the iphone ?

by Frank on Jul 25, 2011. #

I would assume you are correct, this does not prevent the sleep upon user pressing power button.

by John Muchow on Jul 25, 2011. #

Ok thx for the info. Is there a solution available to do this? Showing the Screen is ok, but sometimes the user hit the top button because something happened and later want to return back to the app.

by Frank on Jul 25, 2011. #

I am not aware of any means to capture a press on the Power button…

by John Muchow on Jul 25, 2011. #

You can use the AppDelegate method “appDidResignActive”

by Jakob Halskov on Aug 19, 2011. #

thanks for short and cute code

by ioslover on Aug 30, 2011. #