Getting the screen brightness value in iOS 5

2.9k views Asked by At

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.

1

There are 1 answers

2
sobri On BEST ANSWER

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.