访问iOS中的环境光线传感器

我正在开发一个真正需要访问环境光线传感器的项目。

我在Google和Stackoverflow中search了很多,但是找不到任何有用的信息。 甚至有可能这样做吗?

我也试图通过计算相机input的亮度来计算环境亮度值,但结果并不十分精确,因为相机对图像进行了很多调整,从而导致结果失真。

要读取环境光线传感器数据,您需要在IOKit框架中使用IOHID( 参考 )

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

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

我通过访问相机解决了这个问题

 - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection: (AVCaptureConnection *)connection { CFDictionaryRef metadataDict = CMCopyDictionaryOfAttachments(NULL, sampleBuffer, kCMAttachmentMode_ShouldPropagate); NSDictionary *metadata = [[NSMutableDictionary alloc] initWithDictionary:(__bridge NSDictionary*)metadataDict]; CFRelease(metadataDict); NSDictionary *exifMetadata = [[metadata objectForKey:(NSString *)kCGImagePropertyExifDictionary] mutableCopy]; float brightnessValue = [[exifMetadata objectForKey:(NSString *)kCGImagePropertyExifBrightnessValue] floatValue]; //THIS IS INFORMATION THAT COMES FROM THE SENSOR _Sensor = [[NSNumber numberWithFloat:brightnessValue] stringValue]; NSLog(@" %@",_Sensor); dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ if ([_Sensor isEqualToString:@"-5.575654"]) { // YOU CODE HER } else { // YOU CODE HER } }); }