0

My code:

-(IBAction)changeSlider:(id)sender {

    [[UIScreen mainScreen] setBrightness:slider.value];

    NSString *string = [[NSString alloc] initWithFormat:@"%.1f", slider.value];
    label.text = string;

When I leave my application on backlight brightness 1.0, the brightness stays. How to release it? So it goes back on the usual brightness what you have setup in the settings?

woz
  • 10,888
  • 3
  • 34
  • 64
user1883396
  • 161
  • 3
  • 9

1 Answers1

2

I am not sure if this will work since I dont have a test device in front of me, but you could always store the original brightness somewhere, and then in the AppDelegate, restore the brightness to the original value

- (void)applicationDidEnterBackground:(UIApplication *)application
{
  [[UIScreen mainScreen] setBrightness:originalBrightness];

}
MweyaMutsvene
  • 543
  • 4
  • 15
  • Save the brightness in *applicationDidBecomeActive:*. No reason this wouldn't work ! – rdurand Dec 11 '12 at 16:02
  • originalBrightness is not an Integer so it gives an error. When i try to put the code in applicationDidBecomeActive it only works if you restart the application, not when i press the home button :( – user1883396 Dec 11 '12 at 16:08
  • applicationWillEnterForeground would be a better place to put it. – MweyaMutsvene Dec 11 '12 at 16:10
  • @rdurand the reason is a system bug. It works only when switching between apps, not when home button is pressed. Also, the system should revert to default brightness by itself. My advice is to avoid setting brightness at all. – Sulthan Dec 11 '12 at 16:44
  • If it is a system bug, why does passbook have this feature? – user1883396 Dec 11 '12 at 18:00
  • Sulthan is right, just tested myself, and this looks like a system bug - though it looks like apple probably wont fix it any time soon. I would suggest creating an overlay and change its alpha property instead of using setBrightness. – MweyaMutsvene Dec 12 '12 at 18:09