How can I prevent screen lock only when using Navigation?

Waze has the option to do that, how can I do this in my App?

推荐答案

Use this:

Objective-C:

[[UIApplication sharedApplication] setIdleTimerDisabled: YES];

Swift (legacy):

UIApplication.sharedApplication().idleTimerDisabled = true

Swift 3 and above:

UIApplication.shared.isIdleTimerDisabled = true

Make sure to import UIKit.

Here is the link to the documentation from developer.apple.com.

Ios相关问答推荐

更改文本在Flutter 中的位置

快速相机放大手势不能正常工作

当操作修改查看条件时,按钮不重复

Xcode 15阻止我的应用程序运行:由于实时模式录制的高比率,丢失了1条日志(log)/路标消息?

iOS应用程序冻结在UICollectionView代码,但我没有';没有任何UICollectionViews

封装 Swift 导入

swiftui 图像放大时无法正确拖动

_SKStoreProductParameterAdNetworkSourceIdentifier未定义符号

SwiftUI - ScrollView 不显示底部文本

在所有 tableview / collectionview 中禁用滚动指示器

使用 CIImage 支持的 UIImage 设置 UIImageView 时发生罕见的崩溃

光标未显示在 UITextView 中

Watchkit AppIcon - 名为AppIcon的应用图标集没有任何适用的内容

iOS swift从另一个数组中删除一个数组的元素

在 iOS 7 上更改标签栏色调 colored颜色

在 Xcode 4 中将静态库链接到 iOS 项目

判断密钥是否存在于 NSDictionary 中

单击 GoogleSignIn 按钮时应用程序崩溃

在 iOS 上没有显示数字键盘

值/对象的 NSDictionary 键?