iOS-Swift UIApplication.shared.isIdleTimerDisabled = true 在 AppStore 审核后不起作用

标签 ios swift uiapplication guided-access

努力实现
停止屏幕在某些情况下进入休眠状态 View Controller
我做了什么
我已经在 iOS 12.1.12 上运行的物理 iPhone 6 上使用以下代码测试了我的应用程序。我设置了电话Dislpay & Brigthness > Auto-Lock到 30 秒。我使用 UIApplication.shared.isIdleTimerDisabled = true 在特定的 VC 上运行该应用程序,即使 30 秒后屏幕仍保持亮起。当我在没有 UIApplication.shared.isIdleTimerDisabled = true 的情况下切换到其他 VC 时,屏幕将在 30 秒后关闭。

我分发到 AppStore,我确定我已经上传了正确的版本并从 AppStore 下载了一个新副本,屏幕总是在thingy 根本不工作,屏幕总是在 Auto-Lock 后关闭。环境。

我看过一些文章https://docs.kioskproapp.com/article/899-ios-12-with-guided-access-causing-kiosk-pro-to-sleepisIdleTimerDisabled not working in iOS 12

我试过 Guided Access并打开 Guided AccessMirror Display Auto-Lock > ON .它仍然不适用于 AppStore 的应用程序。请帮忙。

代码

override func viewDidLoad() {

    super.viewDidLoad()
    //==== For the screen to remains on
    UIApplication.shared.isIdleTimerDisabled = true
}


override func viewDidDisappear(_ animated: Bool) {

    //=== Switch off the screen always on, back to the phone settings. 
    UIApplication.shared.isIdleTimerDisabled = false
}

最佳答案

我在 iOS 13 上遇到了同样的问题。我发现了这个 great article解释原因 .isIdleTimerDiabled似乎不起作用。
简而言之,随着iOS 13引入SceneDelegate,只需设置.isIdleTimerDisabled在 AppDelegate 中设置为 false 是不够的,您还需要在 SceneDelegate 中设置它

class SceneDelegate: NSObject, UIWindowSceneDelegate {
    var window: UIWindow?
    
    @available(iOS 13.0, *)
    func sceneDidBecomeActive(_ scene: UIScene) {
        UIApplication.shared.isIdleTimerDisabled = true
    }
}
上面的代码使我的应用程序不受自动锁定的影响,但这只是一个快速的肮脏解决方案,更好的方法是切换 isIdleTimerDisabled根据用户正在使用的 ViewController 开启和关闭,以下是 Apple 关于此属性的文档。

You should set this property (isIdleTimerDisabled) only if necessary and should be sure to reset it to false when the need no longer exists. Most apps should let the system turn off the screen when the idle timer elapses. This includes audio apps. With appropriate use of Audio Session Services, playback and recording proceed uninterrupted when the screen turns off. The only apps that should disable the idle timer are mapping apps, games, or programs where the app needs to continue displaying content when user interaction is minimal.

关于iOS-Swift UIApplication.shared.isIdleTimerDisabled = true 在 AppStore 审核后不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54002649/

相关文章:

ios - 在 Swift 4 中使用掩码使 UIButton 文本透明

ios - 无法正确显示核心数据中的图像

ios - 根据swiftui中单击的切换按钮从数组中删除数据

swift - 从模块 CCurl 调用 curlHelperSetOptString 时出错 - swift -Kitura

Xcode 4.2 模板更改 - UIApplication & MainWindow.xib

ios - 如何在 NSURLSession(Background Session) 事件的情况下测试 Background App Launch?

ios - Unity 在 iPhone 6 Plus 上性能缓慢

ios - 如何为 MapView 上的每个自定义注释添加图像?

pointers - 在 Swift 中,如何确定两个 UnsafePointer 是否引用同一内存?

ios - 处于非事件应用程序状态时的本地通知