WillResignActive和setBrightness不起

WillResignActive和setBrightness不起

本文介绍了applicationWillResignActive和setBrightness不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用[[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:


  1. 激活该应用,将系统亮度设为默认值,然后另存为sysBright。

  1. Active the app, get the system brightness as default, then save as 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];
}

我错过了什么?

推荐答案

我在这里回答了一个类似的问题:

I answered a similar question here: IOS5 setBrightness didn't work with applicationWillResignActive

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 try to switch to another app. Try pressing Home button twice and your brightness is gone.

不要浪费你的时间,只是向苹果( )。

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.

更新:
我的错误报告已关闭,因为根据苹果这不是一个错误。这很奇怪。

UPDATE:My bug report was closed because according to Apple it's not a bug. It is weird.

这篇关于applicationWillResignActive和setBrightness不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!