1
我试图在应用处于后台时控制屏幕的亮度,并且我不确定这是否可行。iOS:在应用处于后台时设置屏幕亮度
this UIScreen brightness documentation注意到
由一个应用程序作出亮度变化保持有效,直到该设备被锁定,而不管该应用程序是否是关闭的。系统亮度(用户可在设置或控制中心中设置)在下次打开显示器时恢复。
这似乎并不是说您不能在后台,应用程序主线程或其他位置设置屏幕亮度。它仅仅表示在锁定/解锁循环中亮度被重置。
考虑下面的代码片段:
backgroundTask = UIApplication.shared().beginBackgroundTask(withName: "something", expirationHandler: handler) // handler ends the background task
registerCallbackForSomeEvent(callback: changeScreenBrightness)
事件无关。我可以在应用程序暂停时打印(),并且一切正常。
和changeSCreenBrightness()
实现是类似以下内容:
func changeScreenBrightness() {
let newBrightness = getNewBrightnessSomehow()
// main or global, it doesn't seem to be happening...
DispatchQueue.main.async(execute: {
// this works in the foreground?! but not the background..
UIScreen.main().brightness = newBrightness
// a print() will be executed however..
})
}
所以..任何人都可以肯定地说,这是不可能的?还是有人有我可以学习的工作代码?
谢谢!