Why can't I set screen brightness in applicationDidEnterBackground or applicationWillResignActive?
This is my code:
-(void)applicationDidEnterBackground:(UIApplication *)application {
[[UIScreen mainScreen] setBrightness:1.0];
}
Can't understand it...!? It works in applicationDidEnterForeground
etc, just not when i close the app using the home button.
Is there any other solution to this problem?
Update August 2016:
Brightness changes made by an app remain in effect until the device is locked, regardless of whether the app is closed. The system brightness (which the user can set in Settings or Control Center) is restored the next time the display is turned on.
https://developer.apple.com/reference/uikit/uiscreen/1617830-brightness
Original Post July 2012:
You're not allowed to set the brightness just before exiting. This is not documented anywhere but the following post on the dev forums is helpful:
https://devforums.apple.com/thread/139813?start=0&tstart=0
What should happen is the system-wide brightness is restored when the app is backgrounded. There is a known bug where this doesn't actually happen until the next time the backlight is switched off and on.
You can reproduce this easily by setting the brightness to 0 and pressing the home key. The home screen will still be very dark. Lock then unlock your device and the system brightness is restored.
Please file a bug about this! On the same post an Apple employee posted that repeated bug reports are helpful.
I never tried to set screen brightness at applicationDidEnterBackground.
I think you can change brightness of your application by using UIView with black background color on top of everything. Then set the alpha of this UIView. Then the result will looks exactly like real screen brightness.
I use this alternative because this method is only available for iOS5.
[[UIScreen mainScreen] setBrightness:1.0];
I want to support iOS3,4 also.