Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Set Image Name in iOS Camera Roll
- (void) imagePickerController: (UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info
[self dismissViewControllerAnimated:YES completion:nil];
UIImage *image = info[UIImagePickerControllerOriginalImage];
NSMutableDictionary *metadata = info[UIImagePickerControllerMediaMetadata];
// set image name and keywords in IPTC metadata
NSString *iptcKey = (NSString *)kCGImagePropertyIPTCDictionary;
NSMutableDictionary *iptcMetadata = metadata[iptcKey];
iptcMetadata[(NSString *)kCGImagePropertyIPTCObjectName] = @"Image Title";
iptcMetadata[(NSString *)kCGImagePropertyIPTCKeywords] = @"some keywords";
metadata[iptcKey] = iptcMetadata;
// set image description in TIFF metadata
NSString *tiffKey = (NSString *)kCGImagePropertyTIFFDictionary;
NSMutableDictionary *tiffMetadata = metadata[tiffKey];
tiffMetadata[(NSString *)kCGImagePropertyTIFFImageDescription] = @"Description for image"; // only visible in iPhoto when IPTCObjectName is set
metadata[tiffKey] = tiffMetadata;
// save image to camera roll
ALAssetsLibrary library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:image.CGImage metadata:metadata completionBlock:nil];

This comment has been minimized.

Copy link

@matrixreal matrixreal commented Feb 13, 2017

i want to use this with jscode ? can you help ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.