IOS5 setBrightness无法与applicationWillResignActive一起使用
我使用 [[UIScreen mainScreen] setBrightness:]
(在sdk 5.0中)更改我应用中的系统背景灯。
I use [[UIScreen mainScreen]setBrightness: ]
(in sdk 5.0) to change the system background light in my app.
以下步骤适用于我的应用程序
The following steps work with my app
-
激活应用程序,默认获取系统亮度,然后另存为
sysBright
。
使用我的应用更改亮度,更改亮度,然后另存为 appBright
。
Change the brightness with my app, changed brightness, then save as appBright
.
带主页按钮或锁定按钮的ResignActive应用程序,将亮度设置为 sysBright
(步骤1值,系统默认亮度)。
ResignActive app with home button or lock button, set brightness to sysBright
(step 1 value, system default brightness).
再次激活应用程序。然后它将重复上述步骤形式1到3.
Active app again. Then it will repeat the above steps form 1 to 3.
第3步出现问题,当我取消激活时使用锁定按钮的应用程序,函数 applicationWillResignActive
效果很好,它可以恢复亮度值( sysBright
)。
Something is wrong with step 3, when I inactivate the app with the lock button, the function applicationWillResignActive
works well, it can restore the brightness value (sysBright
).
但是当我按下主页按钮时,它不再起作用了。亮度仍然是我在我的应用程序中更改的值。 ( appBright
)
But when I press the home button, it doesn't work anymore. The brightness is still the value I changed in my app. (appBright
)
有没有人知道它?感谢您的帮助〜
Does anyone have any idea about it? Thanks for any help ~
以下是代码:
float appBright,sysBright;
- (void)applicationDidBecomeActive:(UIApplication *)application
{
sysBright = [[UIScreen mainScreen] brightness];
[[NSUserDefaults standardUserDefaults] setFloat:sysBright forKey:@"sysBright"];
[[UIScreen mainScreen] setBrightness:appBright];
}
//doesn't work when i ResignActive with the home button
- (void)applicationWillResignActive:(UIApplication *)application
{
[[NSUserDefaults standardUserDefaults] floatForKey:@"sysBright"];
[[UIScreen mainScreen] setBrightness:sysBright];
}
iOS无意保留应用内亮度值。它应该在应用程序重新激活,退出,崩溃等之后恢复系统值。因此,在applicationWillResignActive中没有必要这样做。
iOS is not meant to retain in-app brightness values. It should restore system value after the app resigns active, quits, crashes etc. So officially there is no need to do that in applicationWillResignActive.
但它不起作用。这是一个错误。事实上,如果你切换到另一个应用程序(按两次主页按钮并选择另一个应用程序)它是有效的
But it does't work. It's a bug. In fact it works if you switch to another app (press home button twice and select another app)
不要浪费你的时间只是向Apple提交错误报告(I做得很好。)
Don't waste your time just file a bug report to Apple (I did well).
解锁屏幕恢复默认系统亮度。只需按两下电源按钮并解锁即可恢复原始亮度。
Unlock screen restores default system brightness. Just press the power button twice and unlock to restore original brightness.