I use UIImagePickerController
to pick images in my iOS App and I know exif info can be got by info[UIImagePickerControllerMediaMetadata]
. But when
using and mergind some info from other posts, I approached problem using Dictionary in Swift. I used it in captureOutput of AVFounfation callback for AVCapturePhoto:
func photoOutput(_ output: AVCapturePhotoOutput,
didFinishProcessingPhoto photo: AVCapturePhoto,
error: Error?) {
//retrieve exif information
var photoFormatDescription: CMFormatDescription?
CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, photoPixelBuffer, &photoFormatDescription)
var metadataAttachments: Dictionary = photo.metadata as Dictionary
if var exifData = metadataAttachments["{Exif}"] as? [String: Any] {
exifData[kCGImagePropertyExifUserComment as String] = ""
metadataAttachments[kCGImagePropertyExifDictionary as String] = exifData
}
}
After that "metadataAttachments" is used to build final image (using CGImageDestinationAddImage in my case)
It seems to work (tried in a project build with Swift 4.0)
Hope it can help!