I want iOS code that can show if the screen is lit or not, so that my app can monitor battery power drain due to the (power hungry) backlight activity. This code must use the public API only, as I intend to submit the app to the App Store eventually.
Initially I thought this may be simply a matter of checking the brightness property of the UIScreen, like so:
-(BOOL)isBackLightOn {
float brightness = [UIScreen mainScreen].brightness;
return brightness > 0;
}
but this is incorrect because [UIScreen mainScreen].brightness
represents the value of the slider chosen by the user in the Settings->Brightness screen, not the current light output of the screen.
Apple clearly have a way to determine this value, since it is included in the energy diagnostics that can be viewed in Instruments (e.g. see Logging Energy Usage in an iOS Device), but maybe this measurement has not been exposed through the public API?
A question that may help yo with this is:
Changing Backlight Level, iPhone
It seems that if you include this:
And then using something like this:
Should give you the backlight level. Remember, the screen is always going to have some form of backlight.