2

I've started to use the new iOS 5 brightness setter in UIScreen. Is there a getter property I can use to know what the display brightness is set to on launch?

Thanks very much.

W Dyson
  • 4,604
  • 4
  • 40
  • 68

1 Answers1

11

The same property. These are the methods I use to store the current brightness before changing it, then reset brightness to the previous value later:

- (void)dimScreen {
    previousBrightness = [UIScreen mainScreen].brightness;
    [UIScreen mainScreen].brightness = 0;
}

- (void)restoreScreen {
    [UIScreen mainScreen].brightness = previousBrightness;
}

Update: It's useful to note that the brightness reported by UIScreen is only the brightness the user has set in Settings, and does not report the auto brightness adjusted value. If auto brightness is enabled, I am aware of no way to get the adjusted value.

As an example, if the user has the brightness slider at 100% in Settings but they are currently in a very dark room, then UIScreen will report a brightness of 1.0, but the true value might be closer to 0.5.

sobri
  • 1,626
  • 15
  • 28
  • iOS does not save this value. After lock/unlock your device will end up with the brightness controlled by system settings. – Proud Member Apr 24 '12 at 14:57
  • @MikhaloIvanokov In my example code I'm treating "previousBrightness" as an ivar, so yes, it's your responsibility to retain this value. – sobri Apr 25 '12 at 07:07