Selvin Selvin - 1 year ago 85
iOS Question

Disable automatic screen lock in iOS 5.1

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?



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.

Aki Aki
Answer Source

Just setting [UIApplication sharedApplication].idleTimerDisabled = YES; in

- (BOOL) application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions

works well for me. However, there is a caveat. I have noticed that every time I invoke camera utility to take a snapshot, idleTimerDisable gets set to NO behind the scene. So right after I upload my image, I had to call the following line of code again:

[UIApplication sharedApplication].idleTimerDisabled = YES;

I would not be surprised if there are more places throughout that require same strategy. So far this approach has worked without issues for me.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download