我正在做一个项目,其中它是真的有必要访问环境光传感器。我在Google和Stackoverflow上搜索了很多,但是没有找到任何有用的信息。有可能这样做吗?我还尝试通过计算摄像机输入的亮度来计算环境光值,但结果并不精确,因为摄像机对图像进行了大量调整,从而扭曲了结果。
xeufq47z1#
要读取环境光传感器数据,需要使用IOKit框架中的IOHID(Reference)http://iphonedevwiki.net/index.php/AppleISL29003http://iphonedevwiki.net/index.php/IOKit.framework
bfrts1fy2#
我可能已经太晚了,但我从开发人员文档中了解到SensorKit将允许我们这样做,https://developer.apple.com/documentation/sensorkit/srsensor/3377673-ambientlightsensor
xdnvmnnf3#
我用摄像机解决了这个问题
- (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 } }); }
3条答案
按热度按时间xeufq47z1#
要读取环境光传感器数据,需要使用IOKit框架中的IOHID(Reference)
http://iphonedevwiki.net/index.php/AppleISL29003
http://iphonedevwiki.net/index.php/IOKit.framework
bfrts1fy2#
我可能已经太晚了,但我从开发人员文档中了解到SensorKit将允许我们这样做,
https://developer.apple.com/documentation/sensorkit/srsensor/3377673-ambientlightsensor
xdnvmnnf3#
我用摄像机解决了这个问题