How to re-enable the idle timer in ios once it has been disabled (to allow the display to sleep again)?

僤鯓⒐⒋嵵緔 提交于 2020-02-21 10:44:32

问题


I have figured out how to stop an iOS device from going to sleep (see below), but I am having troubles undoing that setting. According to the Apple Documentation, it should just be changing the value of the idleTimerDisabled property. But when I test this, it does not work.

This is how I am initially stopping the device from going to sleep:

    //need to switch off and on for it to work initially
    [UIApplication sharedApplication].idleTimerDisabled = NO;
    [UIApplication sharedApplication].idleTimerDisabled = YES;

I would have thought that the following would do the trick:

    [UIApplication sharedApplication].idleTimerDisabled = NO;

From the Apple Documentation:


The default value of this property is NO. When most applications have no touches as user input for a short period, the system puts the device into a "sleep” state where the screen dims. This is done for the purposes of conserving power. However, applications that don't have user input except for the accelerometer—games, for instance—can, by setting this property to YES, disable the “idle timer” to avert system sleep.


Important: You should set this property only if necessary and should be sure to reset it to NO when the need no longer exists. Most applications should let the system turn off the screen when the idle timer elapses. This includes audio applications. With appropriate use of Audio Session Services, playback and recording proceed uninterrupted when the screen turns off. The only applications that should disable the idle timer are mapping applications, games, or similar programs with sporadic user interaction.


回答1:


Are you trying this when you Run from Xcode? Running from Xcode always disables the idle timer, regardless if you set [UIApplication sharedApplication].idleTimerDisabled or not. You can try it by manually opening the app from the iPhone/iPod touch/iPad.



来源:https://stackoverflow.com/questions/12856099/how-to-re-enable-the-idle-timer-in-ios-once-it-has-been-disabled-to-allow-the-d

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