jMelnik jMelnik - 5 months ago 24
iOS Question

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

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

Enable the idle timer in

- (void)applicationWillResignActive:(UIApplication *)application

and disable it in

- (void)applicationDidBecomeActive:(UIApplication *)application