【发布时间】:2018-05-26 13:34:39
【问题描述】:
我正在尝试从 UIImagePickerController 中挑选的图像中获取 GPS 数据
我使用this site 作为参考。
选择图片后,CGImageSourceRef 始终为空。
这是我的 NSLog 的输出
信息:{ UIImagePickerControllerMediaType = "public.image"; UIImagePickerControllerOriginalImage = "尺寸 {2448, 3264} 方向 3 比例 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 为空
这是我的代码:
- (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
}
我不确定自己做错了什么。有什么帮助吗?
【问题讨论】:
标签: ios objective-c uiimagepickercontroller