Create a gist now

Instantly share code, notes, and snippets.

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