0
我试图读取的图像的EXIF数据,由用户选择。我正在使用ALAssetLibrary。到目前为止,我已经成功地得到所需assetForURL:resultBlock:failureBlock:
方法参考URL,但是当我试图与参考URL做任何事情,我收到了EXC_BAD_ACCESS
错误。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];
}
}
干杯,即清理我最初的错误。然而,这并创建调用readExifFromSelectedImage方法(当我无论怎么解析的网址相同(EXC_BAD_ACCES)错误,甚至没有一个硬编码[NSURL URLWithString:@“资产库://asset/asset.JPG ID = 1000000003&EXT = JPG“] 有关任何建议吗?[self.report]对象是好的,不同的方法正常工作没有错误。在此先感谢:) – Uxxish 2011-05-16 15:28:39
嗯,它看起来像myAssetLib是不确定的。你声明变量,但不要给它赋值... – omz 2011-05-16 15:46:26
令人难以置信的是我如何忽略这一点。谢谢一堆!现在完美的工作! – Uxxish 2011-05-16 15:48:37