目前我使用的代码可以写入更新后的元数据,但会创建重复图像。以下是代码:
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.");
}
}];
}
有没有什么方法可以避免重复?谢谢您的时间。