快速将用户重置为applicationDidEnterBackground中的默认应用亮度 [英] Reset users default app brightness in applicationDidEnterBackground with swift

查看:117
本文介绍了快速将用户重置为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.

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

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