I have used:
[UIApplication sharedApplication].idleTimerDisabled = YES;
in a number of Apps developed and running under iPhone OS 2.x and never had any problems with it. They were clock apps so needed to run constantly and ignore the iPhone’s idle Timer setting.
However, trying to achieve the same with a new App running OS 3.0 (and which needs to be deployed under 3.0 as it uses some 3.0 APIs) I’ve found the idle Timer to be either ignored or inconsistent.
My App plays music from the iPod library and when the music is playing it auto-locks regardless of the above setting. But once you unlock it, it then doesn’t auto-lock again unless you play music again, in which case it locks again after the iPhone auto-lock time setting.
I’m amazed no-one else has come across this as I imagine it would affect a large number of Apps.
Just to clarify:
1. The above code is in ApplicationDidFinishLaunching
2. I know that the phone won’t auto-lock when testing from xCode regardless of settings
If anyone has any thoughts I’d be very grateful…
Our app uses the
MPMediaPLayer. We also had theidleTimerDisabled=YEScode in theApplicationFinishedLaunching, which works EXCEPT if untethered, and there is already a currentnowPlayingItemwhich is left playing (or unpaused, if paused at app startup). Obviously this is all with theSettings -> General -> Autolockset to some timed value.By adding
idleTimerDisabled=NO, immedately followed byidleTimerDisabled=YESin one of the other bits of code AFTER we had figured out what bit of music we would get playing seemed to solve the problem. Just setting it toYESwas insufficient.. and subsequent queries had always indicated the correct value (YES).. so it appears the Apple code ignores the setting of the value IF there is a current piece of music and that is not changed by your code.. but does notice a change of value.This is all under iOS 3.0.