Hello,
I am trying with swift on ios change and save image metaData. I pick image from ios I get all metaData exift etc. I changed it but.... I can't save it and Ican't how I achieve this.
I can share my code:
if let assetId = imageResult.assetIdentifier {
let assetResults = PHAsset.fetchAssets(withLocalIdentifiers: [assetId], options: nil)
PHImageManager.default().requestImageDataAndOrientation(for: assetResults.firstObject!, options: nil,
resultHandler: { (imagedata, dataUTI, orientation, info) in
if let imageSource = CGImageSourceCreateWithData(imagedata! as CFData, nil) {
let uti: CFString = CGImageSourceGetType(imageSource)!
let dataWithEXIF: NSMutableData = NSMutableData(data: imagedata!)
let destination: CGImageDestination = CGImageDestinationCreateWithData((dataWithEXIF as CFMutableData), uti, 1, nil)!
let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil)! as NSDictionary
let mutable: NSMutableDictionary = imageProperties.mutableCopy() as! NSMutableDictionary
let EXIFDictionary: NSMutableDictionary = (mutable[kCGImagePropertyExifDictionary as String] as? NSMutableDictionary)!
EXIFDictionary[kCGImagePropertyExifUserComment as String] = "type:video"
mutable[kCGImagePropertyExifDictionary as String] = EXIFDictionary
CGImageDestinationAddImageFromSource(destination, imageSource, 0, (mutable as CFDictionary))
CGImageDestinationFinalize(destination)
}
})
How you see I take image with PHAsset.fetchAssets I think is easiest way I change my metaData and I am lost why is not save and how I can achvieve this. Maybe someone can help me figure out?