UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Edit and save image exif metaTada

Forums > Swift

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?

2      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.