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

我已经想出了如何阻止iOS设备进入睡眠状态(见下文),但是我在修复设置方面遇到了麻烦.根据 Apple Documentation,它应该只是改变idleTimerdisabled属性的值.但是当我测试它时,它不起作用.

这就是我最初阻止设备进入睡眠的方式:

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

我原以为会有以下几种方法

[UIApplication sharedApplication].idleTimerdisabled = NO;

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.

有人遇到过这个问题吗?我在iOS6和iOS5上测试.提前致谢.

解决方法

你是从Xcode运行时尝试这个吗?无论您是否设置了[UIApplication sharedApplication] .idleTimerdisabled,从Xcode运行始终会禁用空闲计时器.您可以通过从iPhone / iPod touch / iPad手动打开应用程序来尝试.

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...