Possible to use iphone's light sensory data?

Hi all,

I was wondering if it is possible obtain values from the light sensor(detects light around you to auto adjust brightness) on iphones? Might be useful to implement day/night scene in my game using these values.

I’m interested in this too but I definitely think it will require some custom code if I come up with something il let you know

wow nice keep me updated im definitely interested to know what you come up with!

Unfortunately it appears this is a private framework in iOS, meaning you can’t really use it for App Store games. The best I could find is, to read the brightness settings from the phone, as they COULD correlate with the light outside. (but no guarantee)

You can try and use this code to set the brightness levels: GSEventSetBacklightLevel(); which requires <GraphicsServices/GraphicsServices.h>. This is how one can programmatically adjust the brightness levels. But there is a clause by Apple that if you mess with the brightness, they will remove your application from the app store. Therefore, you can adjust the brightness programmatically only if you are developing a rough app and don’t intend to submit it on the app store.

You can actually use the camera to do this, which is independent of the user’s screen brightness settings (and works even if Automatic Brightness is OFF).
You read the Brightness Value from the video frames metadata using the camera to find out how bright a scene is. Obviously, it only reads the data that can be “seen” in the camera’s field of view, so it’s not a true ambient light sensor.

This line will give you those values:

 NSLog(@"Screen Brightness: %f",[UIScreen mainScreen] brightness]); 

Apple says to not use the framework directly on iOS. Most likely Apple will reject the app regardless of the justification.


wow nice keep me updated I’m definitely interested to know what you come up with!

**Android App Development Company
Hire Android app developers