views:

2718

answers:

5

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...

A: 

Sounds like a bug, file with Radar - I am not too surprised this has not been seen much as there are probably not a lot of apps that try to lock the screen open and play music.

Kendall Helmstetter Gelner
Yeah - I think it's probably a bug - I'll file it.. Thanks.
Craig
A: 

Exact same problem here. Did you find a solution?

Hi - No. There doesn't appear to be a solution. Filed a bug report and hoping it'll get fixed soon.
Craig
A: 

Having same issue. It does work when the device is plugged in. You can press lock button on top, and my NSTimer fires later and causes a vibrate. However if the device is not plugged in pressing the lock button puts the device to sleep. Any solution would be greatly appreciated.

  • iCodeblog posted about the idletimer, I said it didn't work, and the person who develops 'cute clock' was nice enough to reply. You have to do a hack, play a 1 second or longer silent sound every 10 or so seconds with NSTimer. This keeps the device awake even if the user hits the lock button.
Hi - Don't forget that the device won't go to sleep when connected to XCode - it doesn't mean that the idleTimer command is working.There doesn't appear to be a solution yet though.
Craig
A: 

I’m just a complete layman here, but for what it’s worth, I’ve noticed a perhaps relevant problem while running “Tim’s Tourney Timer – Lite Poker Timer” and then “Poker Clock Lite” on my iPhone 3G S. In both cases, the timer counts down fine even when my screen is blank provided that I am simultaneously playing music on the iPhone. But if I am not simultaneously playing music, then once my phone auto-locks or once I lock it out manually, almost no time at all elapses in either app’s timer until I wake up my phone and return to the timer, at which point it immediately resumes counting down. I hope this information either helps you or gives you another couple programs to look at in order to try to figure out what’s going on. I appreciate your post as it enabled me to realized that if I want the timers to function properly, then all I have to do is simultaneously play music. It’s not a very elegant solution, but it’s one I can live with until “the powers that be” fix things by virtue of your instructing them on the problem. Many thanks.

+4  A: 

Our app uses the MPMediaPLayer. We also had the idleTimerDisabled=YES code in the ApplicationFinishedLaunching, which works EXCEPT if untethered, and there is already a current NowPlayingItem which is left playing (or unpaused, if paused at app startup). Obviously this is all with the Settings -> General -> Autolock set to some timed value.

By adding a idleTimerDisabled=NO, immedately followed by a idleTimerDisabled=YES in 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 to YES was insufficient.. and subsequent queries had always indicated the correct (YES) value.. 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 OS 3.0

Neil
Hi Neil - thanks for this. I have actually just found a fix along the same lines. If you set up a timer for every 30 seconds to set the idleTimerDisabled to NO and then YES, it stays on regardless of the music playing settings. It's a bit of a hack but it works!
Craig