Unable to reset brightness on application exit iOS

2020-06-23 05:57发布

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?

2条回答
我想做一个坏孩纸
2楼-- · 2020-06-23 06:42

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.

查看更多
霸刀☆藐视天下
3楼-- · 2020-06-23 06:43

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.

查看更多
登录 后发表回答