问题
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?
回答1:
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.
回答2:
Why don't you try using your code in
applicationWillEnterForeground
delegegate method.
Hope that work's for you.
回答3:
Swift version:
public func applicationWillResignActive(application: UIApplication) {
UIApplication.sharedApplication().idleTimerDisabled = false
}
public func applicationDidBecomeActive(application: UIApplication) {
UIApplication.sharedApplication().idleTimerDisabled = true
}
来源:https://stackoverflow.com/questions/14510285/ios-setidletimerdisabledno-not-working