如何防止 iPhone 屏幕在应用程序运行时变暗或关闭?

发布于 2024-07-05 19:38:58 字数 75 浏览 7 评论 0原文

我正在开发一个不需要用户输入的应用程序,但我不希望 iPhone 进入省电模式。

是否可以通过应用程序禁用省电功能?

I'm working on an app that requires no user input, but I don't want the iPhone to enter the power saving mode.

Is it possible to disable power saving from an app?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

零度° 2024-07-12 19:38:58

斯威夫特3:

UIApplication.shared.isIdleTimerDisabled = true

Swift 3:

UIApplication.shared.isIdleTimerDisabled = true
萧瑟寒风 2024-07-12 19:38:58

swift 中,您可以将其用作

UIApplication.sharedApplication().idleTimerDisabled = true

In swift you can use this as

UIApplication.sharedApplication().idleTimerDisabled = true
若能看破又如何 2024-07-12 19:38:58

Objective-C

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

Swift

UIApplication.shared.isIdleTimerDisabled = true

Objective-C

[[UIApplication sharedApplication] setIdleTimerDisabled:YES];

Swift

UIApplication.shared.isIdleTimerDisabled = true
撩动你心 2024-07-12 19:38:58

我已将这行代码放入视图控制器中,但我们仍然收到客户说屏幕会变暗或关闭,直到有人触摸屏幕。 我看过其他帖子,其中您不仅以编程方式将其设置

UIApplication.sharedApplication().idleTimerDisabled = true 

为 true,而且还必须首先将其重置为 false

UIApplication.sharedApplication().idleTimerDisabled = false
UIApplication.sharedApplication().idleTimerDisabled = true

遗憾的是,这仍然不起作用,客户仍然会看到屏幕变暗的情况。 我们的 Apple Configurator 配置文件阻止设备进入睡眠状态,但仍有一些设备屏幕变暗,客户需要按主页按钮唤醒屏幕。 我现在将此代码放入一个计时器中,该计时器每 2.5 小时触发一次以重置空闲计时器,希望这能起作用。

I have put this line of code in my view controller yet we still get customers saying the screen will dim or turn off until someone touches the screen. I have seen other posts where not only do you programatically set

UIApplication.sharedApplication().idleTimerDisabled = true 

to true but you must reset it to false first

UIApplication.sharedApplication().idleTimerDisabled = false
UIApplication.sharedApplication().idleTimerDisabled = true

Sadly this still did not work and customers are still getting dimmed screens. We have Apple Configurator profile preventing the device from going to sleep, and still some devices screen go dim and the customer needs to press the home button to wake the screen. I now put this code into a timer that fires every 2.5 hours to reset the idle timer, hopefully this will work.

恏ㄋ傷疤忘ㄋ疼 2024-07-12 19:38:58

我们遇到了同样的问题。 事实证明,这是我们的 MDM 服务器上的一个恶意进程,该进程已在我们的帐户中删除,但在服务器上仍在发送命令来调暗我们的设备。

We were having the same issue. Turned out to be a rogue process on our MDM server that was deleted in our account but on the server was still sending the command to dim our devices.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文