ios - Swift: How to Delete EXIF data from picture taken with AVFoundation? -


i'm trying rid of exif data picture taken avfoundation, how can in swift (2) preferred, objective-c okay too, know how convert code swift.

why? have done research , see lot of famous social media (reddit source , many more) remove exif data identity purposes , other purposes.

if think duplicate post, please read i'm asking , provide link. thank you.

my answer based lot on this previous question. adapted code work on swift 2.0.

class imagehelper {   static func removeexifdata(data: nsdata) -> nsdata? {     guard let source = cgimagesourcecreatewithdata(data, nil) else {         return nil     }     guard let type = cgimagesourcegettype(source) else {         return nil     }     let count = cgimagesourcegetcount(source)     let mutabledata = nsmutabledata(data: data)     guard let destination = cgimagedestinationcreatewithdata(mutabledata, type, count, nil) else {         return nil     }     // check keys need remove     // per documentation, if need key removed, assign kcfnull     let removeexifproperties: cfdictionary = [string(kcgimagepropertyexifdictionary) : kcfnull, string(kcgimagepropertyorientation): kcfnull]      in 0..<count {         cgimagedestinationaddimagefromsource(destination, source, i, removeexifproperties)     }      guard cgimagedestinationfinalize(destination) else {         return nil     }      return mutabledata;   } } 

then can this:

let imagedata = imagehelper.removeexifdata(uiimagepngrepresentation(image)) 

in example, remove rotation , exif data. can search keys if need else removed. make checks on data generated optional.


Comments