I am generating image file after processing the image. Location looks something like this "/file:/Users/some_user/Library/Developer/CoreSimulator/Devices/D4C78002-F842-465C-91BE-F7A61239975F/data/Media/DCIM/100APPLE/IMG_0074.JPG"
I am trying to add meta information using swift3 using the following code
let fileURL = NSURL(fileURLWithPath: imageFile.path, isDirectory: false)
guard let source = CGImageSourceCreateWithURL(fileURL as CFURL, nil) else {
return false
}
guard let properties = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as NSDictionary? else {
return false
}
let exifDictionary = (properties.object(forKey: kCGImagePropertyExifDictionary) as? NSMutableDictionary) ?? NSMutableDictionary()
guard let sourceType = CGImageSourceGetType(source) else {
return false
}
let imageData = NSMutableData()
guard let destination = CGImageDestinationCreateWithData(imageData, sourceType, 1, nil) else {
return false
}
...
CGImageDestinationAddImageFromSource(destination, source, 0, newProperties)
CGImageDestinationFinalize(destination)
imageData.write(toFile: imageFile.path, atomically: true)
I am getting nil for the following line but fileURL exists as mentioned above. How can we get CGImageSource in the code
let source = CGImageSourceCreateWithURL(fileURL as CFURL, nil)