setBrightness in appdelegate methods?

自古美人都是妖i 提交于 2020-01-04 05:29:14

问题


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.

Thanks to anyone that can help...


回答1:


It's probably because your app is relinquishing control to the OS, and the OS will then control the brightness according to the user's global settings. If you want to change the brightness setting globally, you'd have to access the user's global iphone settings and change them, and I'm not sure that's possible.

When you're setting the brightness on applicationDidEnterForeground: your app is in control again, and can adjust stuff like brightness. As soon as your app loses that control thought, the OS takes over and brings the device back into compliance with the user's global settings.

Hope that helps.




回答2:


I'm pretty sure this is a bug with the current version (that the setBrightness call has no effect inside of either applicationDidEnterBackground or applicationWillResignActive).

What I do currently is similar to what you arrived at - I set the brightness to 1.0 on application active, and then reduce brightness when needed by modifying the opacity of a black layer on top of all other graphics. That way, if the user suspends the app, then their screen is at least bright (rather than at whatever arbitrary brightness the app was at).

When the user locks their screen, it will be restored to the brightness in their iPhone settings.



来源:https://stackoverflow.com/questions/8317736/setbrightness-in-appdelegate-methods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!