6

I have an app that utilizes the video camera so the screen cannot dim. Inhibiting the screen from dimming works fine like so:

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
}

However when the app is closed and enters the background, setting the IdleTimer back to NO is not working. The screen stays on forever on the home screen. This is how I am trying to accomplish this.

- (void)applicationWillResignActive:(UIApplication *)application
{
    [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
}

Is there a better place to add this line of code?

Kevin_TA
  • 4,575
  • 13
  • 48
  • 77
  • 1
    This may just be a bug with dev builds. I have several apps that force the screen not to dim while they are active, but I've never had one capable of keeping the homescreen or another app on. App settings are almost always app specific to keep the system pure. – Ryan Poolos Jan 24 '13 at 20:44
  • Did you tried this connected to your Mac and XCode? I think that if that the case, the iDevice don't always want to start the "sleep"... – Larme Jan 24 '13 at 20:59
  • @Larme, yea that was my first thought but I unhooked it and it still doesn't dim. – Kevin_TA Jan 24 '13 at 21:07
  • have you tried applicationWillEnterForeground: – Shaun Jan 25 '13 at 00:10
  • 1
    This may sound dumb, but have you checked the sleep interval in settings? This sounds more like a global setting on the phone than an issue with your app – Jack Freeman Feb 21 '13 at 19:29
  • Did you found a solution? I have the same problem, i'm forcing it to stay on for few minutes then disable it, but is never going to sleep. Yesterday i've got asleep myself and the phone stayed on all night. – Cristi Băluță Apr 25 '13 at 11:33

3 Answers3

16

The same problem was occuring with me. Actually it does work but only works when your device is not connected to xCode. Try disconnecting the device and then test this functionality.

Siddhant
  • 430
  • 1
  • 4
  • 12
  • 1
    I spend the whole day trying to figure out the problem but it is because of xcode. you saved my life thanks. – Niib Fouda Oct 25 '16 at 13:37
0

Why don't you try using your code in

applicationWillEnterForeground

delegegate method.

Hope that work's for you.

-1

Swift version:

public func applicationWillResignActive(application: UIApplication) {
    UIApplication.sharedApplication().idleTimerDisabled = false
}


public func applicationDidBecomeActive(application: UIApplication) {
    UIApplication.sharedApplication().idleTimerDisabled = true
}
odemolliens
  • 2,581
  • 2
  • 32
  • 34