代码之家  ›  专栏  ›  技术社区  ›  Hanz Cheah

iOS Swift公司UIApplication.shared.isIdleTimerDisabled=真,在AppStore审核后不工作

  •  0
  • Hanz Cheah  · 技术社区  · 6 年前

    努力实现 停止屏幕进入睡眠状态 View Controller

    我所做的 我已经用以下代码在iOS 12.1.12上运行的物理iPhone6上测试了我的应用程序。我设置了电话 Dislpay & Brigthness > Auto-Lock UIApplication.shared.isIdleTimerDisabled = true ,屏幕在30秒后仍保持打开状态。当我换成其他风投的时候

    我发到AppStore,我肯定我已经上传了正确的版本,并从AppStore下载了一个新的副本,屏幕总是打开的东西根本不起作用,屏幕总是会关闭后的 Auto-Lock 设置。

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

    我试过了 Guided Access 打开了 Mirror 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
    }
    
    0 回复  |  直到 6 年前
        1
  •  4
  •   Daniel Hu    4 年前

    我在iOS13上也遇到过同样的问题。我发现了这个 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关于此属性的文档。

    你应该设置这个属性(