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