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.
No there should be no difference. Perhaps you have another mistake..
See iOS 5.0 to 5.1 API Diffs
Just setting
[UIApplication sharedApplication].idleTimerDisabled = YES;
inworks 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:
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.
For Swift, I use this to do outside of delegate:
Maybe You exceeds the allowable time limit of being awake?
i know its is old, but i found this good and in Swift you can do it look a like this
application.idleTimerDisabled = true
Thanks for you answers! i use right now xcode 7 Beta 3 ( Swift 2 )
Works fine if your application is registered for some background task, for example GPS location updating.