如何仅在使用导航时阻止屏幕锁定。 Waze可以选择这样做,我怎样才能在我的应用程序中执行此操作?
用这个:
Objective-C的:
[[UIApplication sharedApplication] setIdleTimerDisabled: YES];
Swift(遗产):
UIApplication.sharedApplication().idleTimerDisabled = true
迅捷3/4:
UIApplication.shared.isIdleTimerDisabled = true
确保导入UIKit
。
Here是apple.developer.com文档的链接。
对于Swift 3.0,这里有两个选项,具体取决于您要调用代码的位置:
在AppDelegate.swift内:
application.idleTimerDisabled = true
在AppDelegate.swift之外:
UIApplication.shared().isIdleTimerDisabled = true
斯威夫特4
在AppDelegate.swift文件中,在应用程序函数中添加以下行:
application.isIdleTimerDisabled = true
你可以使用我的小lib Insomnia(Swift 3,iOS 9+) - 另一个不错的功能是你可以防止只在充电时睡觉。
qazxsw poi解决方案没问题,但你必须记住之后将它设置为qazxsw poi。