我正在尝试从用户选择的图像中读取 EXIF 数据。我为此使用了 ALAssetLibrary。到目前为止,我已经设法获得了该assetForURL:resultBlock:failureBlock:
方法所需的参考 URL,但是当我尝试对参考 URL 执行任何操作时,我得到了一个EXC_BAD_ACCESS
错误。
URL的一个NSLog
,在使用它之前,会产生(据我所知是正确的)字符串:
assets-library://asset/asset.JPG?id=1000000003&ext=JPG
我一直试图弄清楚这一点,但我似乎每次都陷入死胡同。我必须承认我是 Objective-C 的新手,所以请随意批评我的代码。
代码(远非完整的类,但我认为应该足够了):
//Class_X.m
-(void)readExifDataFromSelectedImage:(NSURL *)imageRefURL
{
void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *) = ^(ALAsset *asset)
{
NSLog(@"Test:Succes");
};
ALAssetsLibrary *myAssetLib;
NSLog(@"%@",imageRefURL);
[myAssetLib assetForURL:imageRefURL
resultBlock:ALAssetsLibraryAssetForURLResultBlock
failureBlock:^(NSError *error){NSLog(@"test:Fail");}];
}
//Class_Y.m
//This also conforms to the UIImagePickerControllerDelegate And the NavigationControllerDelegate protocols:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
self.referenceURL = [info valueForKey:@"UIImagePickerControllerReferenceURL"];
NSString *mediaType = [info
objectForKey:UIImagePickerControllerMediaType];
[self dismissModalViewControllerAnimated:YES];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
imageView.image = selectedImage;
btnNoPicture.hidden = YES;
btnSelectPicture.hidden = YES;
btnTakePicture.hidden = YES;
imageView.hidden = NO;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Use this image?"
message:@"Are you sure you want to use this image?"
delegate:self
cancelButtonTitle:@"No"
otherButtonTitles:@"Yes", nil];
[alert show];
[alert release];
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
//Do not use the selected image.
imageView.image = nil;
imageView.hidden = YES;
//Restart picking process
}
else
{
// I have an instance variable of type Class_X which i use
// throughout this class; let's call this variable "report".
// I also have the referenceURL stored as an instance variable.
[self.report readExifDataFromSelectedImage:self.referenceURL];
}
}