Currently the code I am using can write the updated metadata but creates a duplicate image. Here is the code :
if( [self.textView.text length] != 0 && ![self.userComments isEqualToString: self.textView.text])
{
// This code works but creates a duplicate image
NSMutableDictionary *userCommentDictionary = [NSMutableDictionary dictionary];
[userCommentDictionary setValue:self.textView.text forKey:(NSString *)kCGImagePropertyExifUserComment];
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setValue:userCommentDictionary forKey:(NSString *)kCGImagePropertyExifDictionary];
ALAssetsLibrary *al = [[ALAssetsLibrary alloc] init];
[al writeImageToSavedPhotosAlbum:[self.imageView.image CGImage]
metadata:dict
completionBlock:^(NSURL *assetURL, NSError *error) {
if (error == nil) {
NSLog(@"Image saved.");
self.userComments = self.textView.text;
} else {
NSLog(@"Error saving image.");
}
}];
}
Is there anyway to avoid duplication ? Thanks for your time
As noted in the comment, I don't believe this is possible.
AssetsLibrary doesn't allow modifying of the original asset at all, everything is saved as a new asset with a reference to the original.
With the new PhotoKit library in iOS 8 they do allow modifying of the asset, but I do not see anything there that allows you to modify the metadata either.
Taking a glance at ImageIO there are methods to modify metadata, but again, nothing to save it to the photo library. With this, however, you could probably replace a file on disk with another one with modified exif data.
edit to elaborate: According to answers here it seems like ALAssets provide a URL that does not point to the disk. I believe that means that you have no way of getting the acutual URL of the image to overwrite it, though not in the photos library.
I would suggest you file this as an enhancement to Apple if its that important, if many people request the same thing, they might add it in the future! It does seem that they don't want people messing with this stuff though..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With