{"id":184,"date":"2014-06-04T15:15:30","date_gmt":"2014-06-04T15:15:30","guid":{"rendered":"http:\/\/ootips.org\/yonat\/?p=184"},"modified":"2016-04-17T07:06:09","modified_gmt":"2016-04-17T07:06:09","slug":"how-to-set-the-image-name-when-saving-to-the-camera-roll","status":"publish","type":"post","link":"https:\/\/ootips.org\/yonat\/how-to-set-the-image-name-when-saving-to-the-camera-roll\/","title":{"rendered":"How to Set The Image Name When Saving to The Camera Roll"},"content":{"rendered":"<p>In principle, you can&#8217;t. But in practice, there is a way&#8230; Read on to find out.<\/p>\n<p>iOS names the image IMG_&lt;num> to avoid file name clashes. There is no way to change that from your app.<br \/>\nHowever, if the user later imports an image to iPhoto, then the <b>metadata<\/b> of the image will determine its <b>title<\/b>, <b>description<\/b>, and <b>keywords<\/b>.<br \/>\nIf the user then exports the image to file, iPhoto can use the title for the name of the exported file. (Instructions for doing that are down below, after the code.)<\/p>\n<p>Here is the code to set the metadata and save the image to the camera roll. The code below gets the image from the camera, but this isn&#8217;t necessary &#8211; the image can come from anywhere.<\/p>\n<pre class=\"lang:objc decode:true \">\r\n#import <AssetsLibrary\/AssetsLibrary.h>\r\n#import <ImageIO\/CGImageProperties.h>\r\n\r\n- (void) imagePickerController: (UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info\r\n{\r\n    [self dismissViewControllerAnimated:YES completion:nil];\r\n    UIImage *image = info[UIImagePickerControllerOriginalImage];\r\n    NSMutableDictionary *metadata = info[UIImagePickerControllerMediaMetadata];\r\n\r\n    \/\/ set image name and keywords in IPTC metadata\r\n    NSString *iptcKey = (NSString *)kCGImagePropertyIPTCDictionary;\r\n    NSMutableDictionary *iptcMetadata = metadata[iptcKey];\r\n    iptcMetadata[(NSString *)kCGImagePropertyIPTCObjectName] = @\"Image Title\";\r\n    iptcMetadata[(NSString *)kCGImagePropertyIPTCKeywords] = @\"some keywords\";\r\n    metadata[iptcKey] = iptcMetadata;\r\n\r\n    \/\/ set image description in TIFF metadata\r\n    NSString *tiffKey = (NSString *)kCGImagePropertyTIFFDictionary;\r\n    NSMutableDictionary *tiffMetadata = metadata[tiffKey];\r\n    tiffMetadata[(NSString *)kCGImagePropertyTIFFImageDescription] = @\"Description for image\"; \/\/ only visible in iPhoto when IPTCObjectName is set\r\n    metadata[tiffKey] = tiffMetadata;\r\n\r\n    \/\/ save image to camera roll\r\n    ALAssetsLibrary library = [[ALAssetsLibrary alloc] init];\r\n    [library writeImageToSavedPhotosAlbum:image.CGImage metadata:metadata completionBlock:nil];\r\n}\r\n<\/pre>\n<p>Now the user can import the images to iPhoto and get your programmed title, description, and keywords.<\/p>\n<p>To export the images to files that have the same name as the image title, the user should choose\u00a0<b>File &gt; Export<\/b>\u00a0and then change the\u00a0<b>File Name<\/b>\u00a0field to\u00a0<b>Use title<\/b>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-187\" alt=\"export\" src=\"https:\/\/ootips.org\/yonat\/wp-content\/uploads\/2014\/06\/export.png\" width=\"598\" height=\"460\" srcset=\"https:\/\/ootips.org\/yonat\/wp-content\/uploads\/2014\/06\/export.png 598w, https:\/\/ootips.org\/yonat\/wp-content\/uploads\/2014\/06\/export-300x230.png 300w\" sizes=\"auto, (max-width: 598px) 100vw, 598px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In principle, you can&#8217;t. But in practice, there is a way&#8230; Read on to find out. iOS names the image IMG_&lt;num> to avoid file name clashes. There is no way to change that from your app. However, if the user &hellip; <a href=\"https:\/\/ootips.org\/yonat\/how-to-set-the-image-name-when-saving-to-the-camera-roll\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[1],"tags":[7,6,14,16],"class_list":["post-184","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-ios","tag-iphone","tag-sample-code","tag-workaround"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2aEUP-2Y","_links":{"self":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/comments?post=184"}],"version-history":[{"count":11,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/184\/revisions"}],"predecessor-version":[{"id":241,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/184\/revisions\/241"}],"wp:attachment":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/media?parent=184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/categories?post=184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/tags?post=184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}