I am attempting to get the GPS data from an image that was picked from a UIImagePickerController
I am using this site as a reference.
After the the pick the selected image, the CGImageSourceRef
is always null.
Here is the output from my NSLog
Info: { UIImagePickerControllerMediaType = "public.image"; UIImagePickerControllerOriginalImage = " size {2448, 3264} orientation 3 scale 1.000000"; UIImagePickerControllerReferenceURL = "assets-library://asset/asset.JPG?id=B01DF2C7-B954-41D8-B3FE-6096706DF3BB&ext=JPG"; }
imageFileURL: assets-library://asset/asset.JPG?id=B01DF2C7-B954-41D8-B3FE-6096706DF3BB&ext=JPG
ImageSource was Null
Here is my code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSLog(@"Info: %@", info.description);
[picker dismissViewControllerAnimated:YES completion:^{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSURL *imageFileURL = (NSURL*) info[UIImagePickerControllerReferenceURL];
NSLog(@"imageFileURL: %@", imageFileURL.description);
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((CFURLRef) imageFileURL, NULL);
if (imageSource == NULL) {
NSLog(@"ImageSource was Null");
return;
}
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:NO], (NSString *)kCGImageSourceShouldCache,
nil];
CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, (CFDictionaryRef)options);
CFRelease(imageSource);
CFDictionaryRef gps = CFDictionaryGetValue(imageProperties, kCGImagePropertyGPSDictionary);
if (gps) {
NSString *latitudeString = (NSString *)CFDictionaryGetValue(gps, kCGImagePropertyGPSLatitude);
NSString *latitudeRef = (NSString *)CFDictionaryGetValue(gps, kCGImagePropertyGPSLatitudeRef);
NSString *longitudeString = (NSString *)CFDictionaryGetValue(gps, kCGImagePropertyGPSLongitude);
NSString *longitudeRef = (NSString *)CFDictionaryGetValue(gps, kCGImagePropertyGPSLongitudeRef);
NSLog(@"GPS Coordinates: %@ %@ / %@ %@", longitudeString, longitudeRef, latitudeString, latitudeRef);
}
dispatch_async(dispatch_get_main_queue(), ^{
}); //distpach get main queue
});//background queueu
}];//picker completion
}
I am not sure what I am doing wrong. Any help?