Skip to content

Instantly share code, notes, and snippets.

@hisasann
Created August 3, 2012 03:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hisasann/3244029 to your computer and use it in GitHub Desktop.
Save hisasann/3244029 to your computer and use it in GitHub Desktop.
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