iOS - setIdleTimerDisabled:NO Not Working

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-07 13:52:14

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!