Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Apple has updated their article addressing this issue (Technical Q&amp;A QA1622). If you're using an older version of Xcode, you may still have the article that says, more or less, tough luck, you can't do this without low-level parsing of the image data.</p> <p><a href="https://developer.apple.com/library/ios/#qa/qa1622/_index.html" rel="noreferrer">https://developer.apple.com/library/ios/#qa/qa1622/_index.html</a></p> <p>I adapted the code there as follows:</p> <pre><code>- (void) saveImage:(UIImage *)imageToSave withInfo:(NSDictionary *)info { // Get the assets library ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; // Get the image metadata (EXIF &amp; TIFF) NSMutableDictionary * imageMetadata = [[info objectForKey:UIImagePickerControllerMediaMetadata] mutableCopy]; // add GPS data CLLocation * loc = &lt;•••&gt;; // need a location here if ( loc ) { [imageMetadata setObject:[self gpsDictionaryForLocation:loc] forKey:(NSString*)kCGImagePropertyGPSDictionary]; } ALAssetsLibraryWriteImageCompletionBlock imageWriteCompletionBlock = ^(NSURL *newURL, NSError *error) { if (error) { NSLog( @"Error writing image with metadata to Photo Library: %@", error ); } else { NSLog( @"Wrote image %@ with metadata %@ to Photo Library",newURL,imageMetadata); } }; // Save the new image to the Camera Roll [library writeImageToSavedPhotosAlbum:[imageToSave CGImage] metadata:imageMetadata completionBlock:imageWriteCompletionBlock]; [imageMetadata release]; [library release]; } </code></pre> <p>and I call this from</p> <pre><code>imagePickerController:didFinishPickingMediaWithInfo: </code></pre> <p>which is the delegate method for the image picker.</p> <p>I use a helper method (adapted from <a href="https://github.com/gpambrozio/GusUtils" rel="noreferrer">GusUtils</a>) to build a GPS metadata dictionary from a location:</p> <pre><code>- (NSDictionary *) gpsDictionaryForLocation:(CLLocation *)location { CLLocationDegrees exifLatitude = location.coordinate.latitude; CLLocationDegrees exifLongitude = location.coordinate.longitude; NSString * latRef; NSString * longRef; if (exifLatitude &lt; 0.0) { exifLatitude = exifLatitude * -1.0f; latRef = @"S"; } else { latRef = @"N"; } if (exifLongitude &lt; 0.0) { exifLongitude = exifLongitude * -1.0f; longRef = @"W"; } else { longRef = @"E"; } NSMutableDictionary *locDict = [[NSMutableDictionary alloc] init]; [locDict setObject:location.timestamp forKey:(NSString*)kCGImagePropertyGPSTimeStamp]; [locDict setObject:latRef forKey:(NSString*)kCGImagePropertyGPSLatitudeRef]; [locDict setObject:[NSNumber numberWithFloat:exifLatitude] forKey:(NSString *)kCGImagePropertyGPSLatitude]; [locDict setObject:longRef forKey:(NSString*)kCGImagePropertyGPSLongitudeRef]; [locDict setObject:[NSNumber numberWithFloat:exifLongitude] forKey:(NSString *)kCGImagePropertyGPSLongitude]; [locDict setObject:[NSNumber numberWithFloat:location.horizontalAccuracy] forKey:(NSString*)kCGImagePropertyGPSDOP]; [locDict setObject:[NSNumber numberWithFloat:location.altitude] forKey:(NSString*)kCGImagePropertyGPSAltitude]; return [locDict autorelease]; } </code></pre> <p>So far this is working well for me on iOS4 and iOS5 devices.</p> <p><strong>Update</strong>: and iOS6/iOS7 devices. I built a simple project using this code:</p> <p><a href="https://github.com/5teev/MetaPhotoSave" rel="noreferrer">https://github.com/5teev/MetaPhotoSave</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload