Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
UIImagePickerControllerでイメージピッカーからExif情報を抜き出す
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
NSLog(@"imagePickerController - %@", image.description);
UIImage *editedImage = [editingInfo objectForKey:UIImagePickerControllerEditedImage];
UIImage *originalImage = [editingInfo objectForKey:UIImagePickerControllerOriginalImage];
__weak CameraViewController *__self = self;
NSURL *assetURL = [editingInfo objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:assetURL
resultBlock:^(ALAsset *asset) {
ALAssetRepresentation *representation = [asset defaultRepresentation];
NSDictionary *metadataDict = [representation metadata]; // ←ここにExifとかGPSの情報が入ってる
__self.exif = [metadataDict objectForKey:@"{Exif}"];
// イメージピッカーを隠す
[__self dismissModalViewControllerAnimated:NO];
// ここでプレビュー画面を開く
[__self showCameraConfirmView:image isAlbum:YES exif:__self.exif];
NSLog(@"[metadataDict objectForKey:@\"Exif\"] - %@", [metadataDict objectForKey:@"{Exif}"]);
} failureBlock:^(NSError *error) {
NSLog(@"ALAssetsLibrary error - %@", error);
// エラーの場合はExifは無視する
__self.exif = nil;
// イメージピッカーを隠す
[__self dismissModalViewControllerAnimated:NO];
// ここでプレビュー画面を開く
[__self showCameraConfirmView:originalImage isAlbum:YES exif:__self.exif];
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.