Does iOS send notifications when the system changes screen brightness?

The problem is that there is a button in my reader application that puts it in dark theme mode. Brightness is reduced by 10%. When the user returns to normal mode, he returns to the stored brightness. But at the same time, the real brightness of the system could be changed due to automatic brightness control or even for the user who goes to the settings and changes it.

The problem with the brightness property is that you only ask for the actual brightness of the screen and all that you set is temporary until the user locks the screen. when unlocked, the system returns to system brightness.

If iOS sends notifications when the system changes the brightness, which will be useful. Could not find anything in this document.

+4
source share
2 answers

Find the UIScreenBrightnessDidChangeNotification , which is part of the UIScreen class. It is available from iOS 5.0 and higher.

+6
source

If you want to return the brightness back to the program value when the device is unlocked again, pay attention to the notification UIApplicationDidBecomeActiveNotification and set the brightness to the desired level in your selector.

I did some more research on all this brightness, and here is what I found:

UIScreenBrightnessDidChangeNotification is called ONLY when the system changes brightness or when the user changes brightness from the control panel or settings. NOT when you change the brightness programmatically.

What I suggested from this Apple Doc here (see below) is that after it is programmatically configured, the brightness will no longer change.

The brightness changes made by the application remain valid until the device is locked, regardless of whether the application is closed. The brightness of the system (which the user can set in Settings or the Control Center) is restored the next time the display is turned on.

However, I found that this is not the case (or I misinterpret it). The brightness changes (and UIScreenBrightnessDidChangeNotification is called) after you set the brightness programmatically. However, it ONLY receives a call when the system thinks that it should increase or decrease the brightness (due to changes in the brightness of the environment) *. If the brightness of the environment remains unchanged, your screen will remain as bright as you programmatically.

What does it mean? Well, 2 things:

  • If you want to keep the brightness at the level that you set it programmatically, regardless of the change in environment, you must monitor the UIScreenBrightnessDidChangeNotification level and reset the brightness to the desired level each time it is called.
  • If you want to return to "system" brightness, you really cannot, because you simply cannot say what the brightness of the system would be if there were changes in the environment (because you reset it every time), You have 2 options for this .
    • Remember the brightness before you set your brightness programmatically and return to this value. Or
    • Set the brightness to 0.5 and let the system work with it.

The β€œdanger” in both situations is that it will remain at the value you set until a change in the brightness of the medium is detected.

* There are 2 special cases ... when you set the brightness to 0.0, and the system thinks that it should decrease the brightness, nothing happens, because it is already at 0.0. Secondly, when you set it to 1.0, it will remain at 1.0, regardless of how the environment changes.

+3
source

All Articles