0

I have seen on an iOS application 'Sleep Cycle Alarm Clock' that when the iPhone is facing screen down (towards the floor) they have managed to dim the back light of the screen. I have been searching all over the internet and can't find the API that provides this functionality.

I am guessing that they achieve this by measuring acceleration on the device from gravity and dimming the back light accordingly, which I have no problem with. I just don't know how they have dimmed the back light (including the status bar!). It's not a semi-transparent black UIView overlayed on the superview, the light definitely switches off.

The detection isn't the issue, it's the dimming that I don't know how to do.

Can anyone point me to the correct method/API documentation? I'm using the iOS 6 SDK.

Thanks

EDIT:

Sorry guys, appears that I was wrong. Further investigation leads me to believe they haven't dimmed the backlight. The instructions stay over the superview temporarily. I think they actually overlay a black image and remove the status bar. My apologies! To get around the orientation lock for orientation detection I think they use the accelerometer.

Adam Waite
  • 19,175
  • 22
  • 126
  • 148

2 Answers2

0

Detecting if the device is face down can be done by using UIDevice orientation. This will return UIDeviceOrientationFaceDown when the screen is facing toward the floor.

Have a look at the UIScreen class for a couple of methods related to brightness.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Thanks for the answer, but the detection isn't the issue. Thanks. – Adam Waite Nov 07 '12 at 18:30
  • Then please clarify your question with what help you really need. I also pointed you to methods for changing the screen brightness. – rmaddy Nov 07 '12 at 18:32
  • Yeah, I know of this -> [[UIScreen mainScreen] setBrightness:0.1]; but that causes problems with the application delegate and appwillresignactive etc. I'm pretty sure they haven't used that. I think there's something else. – Adam Waite Nov 07 '12 at 18:36
  • OK. If you had posted what you already knew and tried in your question, it would save people time trying to help. Good luck. – rmaddy Nov 07 '12 at 18:40
  • 1
    They could of achieved this with private APIs, refer to: http://stackoverflow.com/questions/366889/change-backlight-brightness-on-iphone-programmatically – Colin Swelin Nov 07 '12 at 18:42
  • Aha, this looks more like it. But private APIs-> rejection right? Might just gamble... – Adam Waite Nov 07 '12 at 19:12
0

Try this:

[[UIScreen mainScreen] setBrightness:0.5]; //Any value you think works

for more information about UIScreen and what you can do with it look at the documentation:

UIScreen Apple Documentation

EDIT: Just read the comments on the other answer, what kind of problems does this method cause?

pedros
  • 1,197
  • 10
  • 18