This is how I solved the problem:
1) I saved the file without metadata in some place and saved its urlpath.
2) Then the following code fragment was used to save the same metadata file. Here fileURL is the urlpath obtained from step 1.
CFURLRef url = CFURLCreateFilePathURL(NULL, (CFURLRef)fileURL, NULL);
CGImageSourceRef imageSource = CGImageSourceCreateWithURL(url, NULL);
CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault, 0);
CGImageDestinationRef imageDestination = CGImageDestinationCreateWithData(data, CFSTR("public.jpeg"), 1, NULL);
BOOL success = (imageSource != NULL);
require(success, cleanup);
success = (imageDestination != NULL);
require(success, cleanup);
NSDictionary *metadata = someObj.metadata;
CGImageDestinationAddImageFromSource(imageDestination, imageSource, 0, (CFDictionaryRef)metadata);
success = CGImageDestinationFinalize(imageDestination);
require(success, cleanup);
[(NSMutableData *) data writeToURL:fileURL atomically:YES];
Cleaning:
if (data) {
CFRelease(data);
data = NULL;
}
if (imageSource) {
CFRelease(imageSource);
imageSource = NULL;
}
if (imageDestination) {
CFRelease(imageDestination);
imageDestination = NULL;
}
return success;
, . H2C03 , . , , . .