使用 swift 在 applicationDidEnterBackground 中重置用户的默认应用程序亮度 [英] Reset users default app brightness in applicationDidEnterBackground with swift

查看:26
本文介绍了使用 swift 在 applicationDidEnterBackground 中重置用户的默认应用程序亮度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用以下代码在应用委托方法中重置用户的默认设备亮度: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:

应用程序所做的亮度更改仅在应用程序活跃.系统恢复用户提供的亮度设置您的应用不在前台的适当时间.

Brightness changes made by an app remain in effect only while the app is active. The system restores the user-supplied brightness setting at appropriate times when your app is not in the foreground.

这篇关于使用 swift 在 applicationDidEnterBackground 中重置用户的默认应用程序亮度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆