阅读iPhone的环境光传感器

时间:2021-10-05 09:20:12

I notice on my iPhone, after a few seconds of being in direct sun light, the screen will adjust to become brighter, dimmer etc. I was wondering if there was a way to interact with this sensor?

我注意到在我的iPhone上,在阳光直射几秒后,屏幕会调整为更亮,更暗。我想知道是否有办法与这个传感器进行交互?

I have an application which is used outside. When you go into direct light, it becomes very difficult to see the screen for a few momments, before it adjusts. And even then, it's not always as bright as I'd like it to be. I would like to implement a high contrast skin for outdoor viewing, and a low contrast for indoor viewing.

我有一个在外面使用的应用程序。当你进入直接光线时,在调整之前很难看到屏幕上的几个元素。即便如此,它并不总是像我希望的那样明亮。我想在户外观看时使用高对比度皮肤,在室内观看时使用低对比度。

Is this possible to read light sensor data, and if so, how do I extract these sensor values?

这是否可以读取光传感器数据,如果是这样,我如何提取这些传感器值?

I would assume there is a light sensor however, as the camera knows when to use the flash.

我会假设有一个光传感器,因为相机知道何时使用闪光灯。

4 个解决方案

#1


5  

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.

尝试使用GSEventSetBacklightLevel();,这需要 。这是人们可以通过编程方式调整亮度级别的方法。还有一个获取选项,所以我认为可能有你想要的信息。

#2


19  

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)

从0.12(暗)到0.99(光)

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.

问候。

#3


10  

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

要读取环境光传感器数据,您需要在IOKit框架中使用IOHID。

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

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

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

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.

但是,这需要私有标头,因此如果您使用它,Apple可能不会让您的应用程序进入应用程序商店。

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

我不断向iOS论坛询问将来是否会支持环境光传感器读数,但无济于事。

#4


7  

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.

您可以从视频帧的元数据中读取亮度值,正如我在此Stack Overflow答案中所解释的那样。

#1


5  

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.

尝试使用GSEventSetBacklightLevel();,这需要 。这是人们可以通过编程方式调整亮度级别的方法。还有一个获取选项,所以我认为可能有你想要的信息。

#2


19  

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)

从0.12(暗)到0.99(光)

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.

问候。

#3


10  

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

要读取环境光传感器数据,您需要在IOKit框架中使用IOHID。

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

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

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

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.

但是,这需要私有标头,因此如果您使用它,Apple可能不会让您的应用程序进入应用程序商店。

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

我不断向iOS论坛询问将来是否会支持环境光传感器读数,但无济于事。

#4


7  

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.

您可以从视频帧的元数据中读取亮度值,正如我在此Stack Overflow答案中所解释的那样。