Reading the iPhone's Ambient Light sensor

人走茶凉 提交于 2019-11-28 16:53:30

Try using GSEventSetBacklightLevel();, which requires <GraphicsServices/GraphicsServices.h>. This is how one can programmatically adjust the brightness levels. There is also a get option, so I think that may have the information you're after.

On the other hand this is a different idea (maybe a silly one), using the brightness of the device's screen you can get some value of the external conditions.

From 0.12 (Dark) to 0.99 (Light)

The next line will get those values, give it a try, put some light on and off over the device to get different values.

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

Obviously Automatic Brightness feature should be turned on in order to get this to work.

Regards.

To read the ambient light sensor data, you need to use IOHID in the IOKit framework.

http://iphonedevwiki.net/index.php/AppleISL29003

http://iphonedevwiki.net/index.php/IOKit.framework

However, this requires private headers, so if you use it, Apple probably won't let your app into the app store.

I continually ask the iOS forums whether there will be support for ambient light sensor readings in the future, but to no avail.

Wildaker

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 as I explain in this Stack Overflow answer.

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