问题描述
我一直在尝试使用以下代码在应用委托方法中重置用户的默认设备亮度:applicationDidEnterBackground
:
I've been trying to reset the user's default device brightness in the app delegate method: applicationDidEnterBackground
by using this code:
UIScreen.mainScreen().brightness = screenBrightness!
代码被调用,但亮度没有重置.任何人都知道如何使用 Swift(而不是 obj-c)让这个工作
The code gets called but the brightness is not reset. Anyone know how to get this working using Swift (not obj-c)
推荐答案
这段代码看起来是正确的,但是注意在模拟器上是不行的,只能在物理设备上生效.
This code looks correct, but note that it will not work in the simulator, it will only take effect on a physical device.
另外,确保screenBrightness
的值在0到1之间.
Also, ensure that the value of screenBrightness
is between 0 and 1.
您可能无法在后台更改屏幕亮度.来自 Apple 的文档:
You will likely not be able to change the screen brightness while in the background. From Apple's documentation:
应用程序所做的亮度更改仅在应用程序活跃.系统恢复用户提供的亮度设置您的应用不在前台的适当时间.
这篇关于使用 swift 在 applicationDidEnterBackground 中重置用户的默认应用程序亮度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!