ios - 如何在 iOS 上使用 swift 防止应用程序屏幕锁定

标签 ios swift locking screen

如何防止仅在使用导航时屏幕锁定?

Waze 可以选择执行此操作,我如何在我的应用程序中执行此操作?

最佳答案

使用这个:

Objective-C:

[[UIApplication sharedApplication] setIdleTimerDisabled: YES];

Swift(旧版):

UIApplication.sharedApplication().idleTimerDisabled = true

Swift 3 及以上版本:

UIApplication.shared.isIdleTimerDisabled = true

确保导入 UIKit

Here是来自developer.apple.com 的文档链接。

关于ios - 如何在 iOS 上使用 swift 防止应用程序屏幕锁定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60071380/

相关文章:

iphone - 核心数据 : Ubiquity: Using local storage: 1 never becomes 0

objective-c - 调用 [alert show] 后 UIAlertView 未立即显示

ios - 更改 UIBarButton 内按钮内图标的颜色(Swift)

ios - Swift 4 - 用负数编辑标签 frame.size.height

swift - 检查 NSAlert 当前是否显示

c++ - mutex.timed_lock(duration) 和 boost::timed_mutex::scoped_lock 之间的区别 scoped_lock(mutex, duration)

c++ - 以固定速率重播存储的数据

ios - Xcode:应用程序传输安全

c++ - boost 互斥顺序

iphone - 如何在 iOS 中实现复制和粘贴功能