Is .brightness Key Value Observable?

This is what I am truing to do on this iO7 or later app:

When the user opens my app, I want to get the screen brightness value and turn up the brightness all the way. When the user leaves the app, I want the brightness to go back to previous value.

So far I use this:

-(void) applicationWillResignActive
    [[UIScreen mainScreen] setBrightness:oldScreenBrightness];

-(void) applicationDidBecomeActive
    screenBrightness = [UIScreen mainScreen].brightness;
    [[UIScreen mainScreen] setBrightness:1.0];

This works fine, except, if the user adjusts the brightness via Control Center WHILE using the app, it will still go back to the old brightness upon leaving the app when it should not.

So I was wondering, if I can Key Value Observe [UIScreen mainScreen].brightness and check if it's changed by the user to omit changing it back to old value....


According to the Apple Developer docs:

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. So if you change the value of this property, you do not need to record the previous value and restore it when your app moves to the background.

I think you're overcomplicating it. On your way out, check the current brightness level. If it's 1.0, switch it back to whatever you got when you started. If it's anything but 1.0, you can feel fairly confident that the user changed it to something else, so do nothing.

It's also probably best to create some kind of constant for your screen brightness to make the code more readable and the intention clear.

static const CGFloat kAppConfiguredBrightness = (CGFloat)1.;

  UIScreen* screen = [UIScreen mainScreen];
  if (screen.brightness == kAppConfigredBrightness) {
    screen.brightness = oldScreenBrightness;

Need Your Help

Blendability for ViewModel instances in MVVM Light

c# wpf mvvm mvvm-light

I've used MVVM before, but MVVM-Light confuses the hell out of me, so I'm sorry if this is dumb (it's just that there's barely any documentation).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.