How to disable iPhone/iPad auto-lock while app is in foreground mode?

jMelnik picture jMelnik · Feb 23, 2012 · Viewed 20k times · Source

I'm developing an music/video player app and just need to konw how to disable the auto-lock while my app is in foreground.

I know I've to use [[UIApplication sharedApplication] setIdleTimerDisabled:YES]; and [[UIApplication sharedApplication] setIdleTimerDisabled:NO]; at some point, but where is the best place to put them?

Answer

Erik Aigner picture Erik Aigner · Feb 23, 2012

Enable the idle timer in

- (void)applicationWillResignActive:(UIApplication *)application

and disable it in

- (void)applicationDidBecomeActive:(UIApplication *)application