简体   繁体   English

如何在禁用ios时重新启用空闲计时器(允许显示再次进入睡眠状态)?

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

I have figured out how to stop an iOS device from going to sleep (see below), but I am having troubles undoing that setting. 我已经想出了如何阻止iOS设备进入睡眠状态(见下文),但是我在修复设置方面遇到了麻烦。 According to the Apple Documentation , it should just be changing the value of the idleTimerDisabled property. 根据Apple文档 ,它应该只是更改idleTimerDisabled属性的值。 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 : 来自Apple文档


The default value of this property is NO. 此属性的默认值为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. 当大多数应用程序在短时间内没有作为用户输入的触摸时,系统将设备置于屏幕变暗的“睡眠”状态。这样做是为了节省电力。但是,没有用户输入的应用程序除了加速计 - 游戏,例如-can,通过将此属性设置为YES,禁用“空闲计时器”以避免系统睡眠。


Important: You should set this property only if necessary and should be sure to reset it to NO when the need no longer exists. 重要提示:您应该仅在必要时设置此属性,并且当需要不再存在时,应确保将其重置为NO 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. 应该禁用空闲计时器的唯一应用程序是通过零星的用户交互来映射应用程序,游戏或类似程序。

Are you trying this when you Run from Xcode? 你是从Xcode运行时尝试这个吗? Running from Xcode always disables the idle timer, regardless if you set [UIApplication sharedApplication].idleTimerDisabled or not. 无论您是否设置了[UIApplication sharedApplication].idleTimerDisabled ,从Xcode运行始终会禁用空闲计时器。 You can try it by manually opening the app from the iPhone/iPod touch/iPad. 您可以通过从iPhone / iPod touch / iPad手动打开应用程序来尝试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM