3

I am making a clock app and I wanted to know how can I check what the current brightness level is set to and how can i adjust brightness in my application in xcode 4 with a UISlider instead of telling the user to go to their iphone/ipad setting app and adjust the brightness there? I can't find any code/api for it.

I have seen quite a few clock apps in appstore where the user can adjust the brightness of the display just by moving the finger up or down.

Sam B
  • 27,273
  • 15
  • 84
  • 121

1 Answers1

11

You're looking for the brightness property of UIScreen.

Sample code:

[UIScreen mainScreen].brightness = 0.5;

Available in iOS 5.0 and later.

Rany Ishak
  • 2,008
  • 2
  • 19
  • 19
jrturton
  • 118,105
  • 32
  • 252
  • 268
  • and it as available in iOS5+ only. – holex Jul 23 '12 at 15:02
  • 1
    the problem I see with this approach is that its just a temporary fix. If the user leaves my clock screen and comes back to it again then he will have to adjust the brightness again? Would that be right? – Sam B Jul 23 '12 at 15:07
  • If you exit the app with the home button, the brightness setting is kept. If you then put the phone in standby and come back, the original brightness is returned. There are other questions on SO asking about this inconsistency! There is no other API than this for setting the screen brightness, and global settings will never be alterable from a third party app. – jrturton Jul 23 '12 at 15:11
  • http://stackoverflow.com/questions/8316358/applicationwillresignactive-and-setbrightness-not-working for an example of the inconsistency – jrturton Jul 23 '12 at 15:15