gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 02:53:28 24 4
gpt4 key购买 nike

努力实现
停止屏幕在某些情况下进入休眠状态 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com