UIScreen Brightness Property
Asked Answered
D

2

6

At the moment I'm trying to create an application to adjust the device's brightness. In iOS5, there is the new brightness property for mainScreen that allows you to set the screen brightness. I'm using the following code:

[[UIScreen mainScreen] setBrightness:1.0];

However this seems to only work until the device is locked, and doesn't get saved in settings. Is there something I'm doing wrong?

Deserved answered 26/10, 2011 at 9:30 Comment(0)
C
3

You will need to save the value you want to set yourself in your NSUserDefaults and call setBrightness: in your application delegate's applicationDidBecomeActive: method to restore the brightness.

Cwm answered 26/10, 2011 at 10:18 Comment(2)
Thanks, is there no way to have the device's brightness set permanently using public APIs?Deserved
I don't think so, and I wouldn't want that anyway. It may make sense for certain apps to lower/raise the brightness, but I wouldn't want these apps to mess with my device brightness. If everytime you enter such an app, your brightness would be changed which would be very annoying.Cwm
I
0

It sets the brightness for the device on iPad, and iPhone, just like in the Settings. It changes the brightness even when the app closes, it is kind of annoying. You have to reset it back to default programmatically in the appropriate method. I just created a tracing table app, Lite Box, and noticed it does not go back to the initial setting, even when app is force closed. You have to reopen app....set back to default, or go to your Settings and change it back.

Infundibuliform answered 15/4, 2014 at 13:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.