Search code examples
iphoneiosipadforegroundauto-lock

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?


Solution

  • Enable the idle timer in

    - (void)applicationWillResignActive:(UIApplication *)application
    

    and disable it in

    - (void)applicationDidBecomeActive:(UIApplication *)application