Is there a way to use the iPhone proximity sensor to detect whether the phone is in a room with no light?
This question seems to imply that this is not possible...Do
Swift 4.2 version based upon Wildaker's code. Xcode 10 refused to allow it to be a Float, but the double has worked.
func getBrightness(sampleBuffer: CMSampleBuffer) -> Double {
let rawMetadata = CMCopyDictionaryOfAttachments(allocator: nil, target: sampleBuffer, attachmentMode: CMAttachmentMode(kCMAttachmentMode_ShouldPropagate))
let metadata = CFDictionaryCreateMutableCopy(nil, 0, rawMetadata) as NSMutableDictionary
let exifData = metadata.value(forKey: "{Exif}") as? NSMutableDictionary
let brightnessValue : Double = exifData?[kCGImagePropertyExifBrightnessValue as String] as! Double
return brightnessValue
}