Search code examples
iosjailbreak

How to make brightness change permanent in iOS?


GSEventSetBacklightLevel(BrightnessSlider.value); 

[[UIApplication sharedApplication] setBacklightLevel:BrightnessSlider.value];

iOS UIScreen has brightness property. Setting it to a different value updates screen brightness. But after lock / unlock screen brightness is restored to whatever brightness is set in iOS Settings.

Must I make a call to save the setting? Is there a sync call or something?

This is a jailbreak development,No "sandbox"。


Solution

  • The UIApplication setBacklightLevel: call is indeed temporary.

    However, if you look at the code to toggle (change) brightness level in SBSettings, that is a permanent setting. I do still think that any change in brightness is also affected by whether or not the user has the Settings -> Brightness -> Auto-Brightness feature turned on. Auto-Brightness will dynamically adjust the screen brightness.

    Take a look at this page. Scroll to the bottom to see this link.

    As you can see, a permanent brightness change is achieved by writing the new brightness level to the com.apple.springboard.plist file:

        NSMutableDictionary* Prefs = [NSMutableDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/com.apple.springboard.plist"];
    
        if(Prefs != nil)
        {
            NSLog(@"Prefs != nil\n");
            float CurrentBacklight1 = [[Prefs objectForKey:@"SBBacklightLevel"] floatValue];
            float CurrentBacklight2 = [[Prefs objectForKey:@"SBBacklightLevel2"] floatValue];
            NSNumber* Number = [NSNumber numberWithFloat:CurrentBacklight];
    
            if(CurrentBacklight2 > 0)
            {
                NSLog(@"CurrentBacklight2 = %f\n", CurrentBacklight2);
                [Prefs setObject:Number forKey:@"SBBacklightLevel2"];
            }
            if(CurrentBacklight1 > 0)
            {
                NSLog(@"CurrentBacklight1 = %f\n", CurrentBacklight1);
                [Prefs setObject:Number forKey:@"SBBacklightLevel"];
            }
            [Prefs writeToFile:@"/var/mobile/Library/Preferences/com.apple.springboard.plist" atomically:YES];
        }
    

    which contains the values that you are seeing SpringBoard revert to. And, then the change is also applied temporarily with the code you're using:

    [[UIApplication sharedApplication] setBacklightLevel:BrightnessSlider.value];
    

    The combination of these two changes should get you what you want.