I need to use the iOS device camera to take a photo and then upload it to the server. The problem is that, by default, the UIImage taken form UIImagePickerController info does not include GPS metadata.
Following this post I have been able to save the image in the Camerra Roll with the correct GPS info. The code used is the following one:
- (void)saveImage:(UIImage *)imageToSave withInfo:(NSDictionary *)info {
// Get the image metadata (EXIF & TIFF)
NSMutableDictionary * imgMtd = [[info objectForKey:UIImagePickerControllerMediaMetadata] mutableCopy];
// create CLLocation for image
locationManager = [[CLLocationManager alloc] init];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
CLLocation * loc = [locationManager location];
if (loc) {
[imgMtd setObject:[self gpsDictionaryForLocation:loc] forKey:(NSString*)kCGImagePropertyGPSDictionary];
}
// Get the assets library
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// create a completion block for when we process the image
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,imgMtd);
}
};
// Save the new image to the Camera Roll, using the completion block defined just above
[library writeImageToSavedPhotosAlbum:[imageToSave CGImage] metadata:imgMtd completionBlock:imageWriteCompletionBlock];
}
However, I am using this photo to upload it to a server. Therefore, the desired behavior is to save it at a temporal path (so the image won't be available at the Camera Roll), upload it to the server and then delete it. With the code provided, I am making the image public, and don't know its path to upload it.