I am trying to get the exposure time from an image captured using AVFoundation
. When I followed the 2010's WWDC instruction about retrieving useful image metadata from CMSampleBuffer
like this:
-(void)captureStillImageWithCompletion:(completion_exp)completionHandler
{
AVCaptureConnection *connection = [stillImage connectionWithMediaType:AVMediaTypeVideo];
typedef void(^MyBufBlock)(CMSampleBufferRef, NSError*);
MyBufBlock h = ^(CMSampleBufferRef buf, NSError *err){
CFDictionaryRef exifAttachments = CMGetAttachment(buf, kCGImagePropertyExifDictionary, NULL);
if(exifAttachments){
NSLog(@"%@",exifAttachments);
}
if(completionHandler){
completionHandler();
}
};
[stillImage captureStillImageAsynchronouslyFromConnection:connection completionHandler:h];
}
I had an error on the CFDictionaryRef
line:
Cannot initialize a variable of type'CFDictionaryRef (aka 'const __CFDictionary*') with an rvalue of type CFTypeRef..
So I followed a solution in the internet by casting it like this:
CFDictionaryRef exifAttachments = (CFDictionaryRef)CMGetAttachment(buf, kCGImagePropertyExifDictionary, NULL);
And now it gives me another error: Undefined symbols for architecture armv7s
(Apple Mach-o Linker Error: "_kCGImagePropertyExifDictionary", referenced from:)
(Apple Mach-o Linker Error: "_CMGetAttachment", referenced from:)
I don't understand what went wrong with my program. Anybody has any idea?
EDIT: You have to include ImageIO library and header to make this key work. If you do not want to do that you can use this:
There's something about the key I think. This worked for me: