I had exactly the same problem. I think that the documentation on this topic is small, so I solved it at the end, looking at the metadata of the photo taken by the Camera application, and tried to reproduce it.
Here is a run of the properties that the camera application saves:
- kCGImagePropertyGPSLatitude
(NSNumber) ( )
- kCGImagePropertyGPSLongitude
(NSNumber) ( )
- kCGImagePropertyGPSLatitudeRef
(NSString) ( N, S)
- kCGImagePropertyGPSLongitudeRef
(NSString) ( E, W)
- kCGImagePropertyGPSTimeStamp
(NSString) ( 04: 30: 51,71
( UTC))
, . :
CFDictionaryRef metaDict = CMCopyDictionaryOfAttachments(NULL, imageDataSampleBuffer, kCMAttachmentMode_ShouldPropagate);
CFMutableDictionaryRef mutable = CFDictionaryCreateMutableCopy(NULL, 0, metaDict);
NSDictionary *gpsDict = [NSDictionary
dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat:self.currentLocation.coordinate.latitude], kCGImagePropertyGPSLatitude,
@"N", kCGImagePropertyGPSLatitudeRef,
[NSNumber numberWithFloat:self.currentLocation.coordinate.longitude], kCGImagePropertyGPSLongitude,
@"E", kCGImagePropertyGPSLongitudeRef,
@"04:30:51.71", kCGImagePropertyGPSTimeStamp,
nil];
CFDictionarySetValue(mutable, kCGImagePropertyGPSDictionary, gpsDict);
NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:[image CGImage] metadata:mutable completionBlock:captureComplete];
completeHandler captureStillImageAsynchronouslyFromConnection AVCaptureConnection, self.currentLocation - CLLocation. Lat/Lng Refs , .
, !