1

I have been reading through questions* and answers about how to stop an iOS device from suspending, starting with the most general to more specific questions that discuss problems with this code:

[UIApplication sharedApplication].idleTimerDisabled = YES;

Some suggest turning it to NO before turning it on (sounds bogus but who knows), some suggest that you need to turn it on often (what?), and other such advice. Also, most of the advice is from iOS 3.0.

Is anybody using this in iOS 5, and what are the caveats with its use? I do not want the device to suspend (auto-lock) at any time if my app is in the foreground (battery be damned). Will idleTimerDisabled do this?


* A lot of info out here: https://stackoverflow.com/search?q=auto-lock+ios
Community
  • 1
  • 1
Dan Rosenstark
  • 68,471
  • 58
  • 283
  • 421

1 Answers1

3

Set it in applicationDidBecomeActive: and unset it in applicationWillResignActive: and you should have no problems.

Most of the times when people have a problem with it "not working" the user has switched to some other app (e.g. camera) and they are expecting their setting to magically be restored!

I have an app in the app store the uses this and have had no complaints of it not working so far. Depending on your app you may want to give the user the option of turning this on and off.

idz
  • 12,825
  • 1
  • 29
  • 40
  • Thanks muchly. Anecdotal evidence is the best we can do for iOS :) – Dan Rosenstark Aug 15 '12 at 00:16
  • So `applicationDidBecomeActive` fires at first launch, too, right? – Dan Rosenstark Aug 15 '12 at 00:21
  • 1
    Yes, it is called after `application:didFinishLaunchingWithOptions:` – idz Aug 15 '12 at 01:38
  • i had idle timer disabling in my code since iOS 3.x days and it worked just fine, but recently, something in iOS 6.x changed, and it stopped working reliably as I expected. I re-implemented it in …BecomeActive and …ResignActive and all is good again. – deeje cooley Aug 18 '13 at 19:28