Skip to content

Instantly share code, notes, and snippets.

@yonat
Last active March 16, 2017 10:01
Show Gist options
  • Save yonat/e26fcf0991dfff6daab1 to your computer and use it in GitHub Desktop.
Save yonat/e26fcf0991dfff6daab1 to your computer and use it in GitHub Desktop.
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];
}
@matrixreal
Copy link

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