Disable automatic screen lock in iOS 5.1

Selvin picture Selvin · Mar 28, 2012 · Viewed 24k times · Source

The following line of code prevents the app from automatically locking the screen after some idle time.

[UIApplication sharedApplication].idleTimerDisabled = YES; //write this in applicationDidFinishLaunching

It works well till iOS 5.0. But iOS 5.1 does not respect this line and locks the screen after some idle time. How to solve this irritating issue?

Thanks.

Edit:

The same code works fine when its installed in 5.0.1 device. But I dont know why it is not working with 5.1 device.

Answer

orkoden picture orkoden · Jul 4, 2012
[[UIApplication sharedApplication] setIdleTimerDisabled: YES];

worked for me on iOS 5.1