我有以下方法在拍摄照片后从ALAsset
检索UIImagePicker
。然后它尝试通过主线程将此ALAsset
发送到我的另一个方法:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL *imageURL = [[info valueForKey:UIImagePickerControllerReferenceURL] retain];
__block ALAsset *result;
[self.assetsLibrary assetForURL:imageURL resultBlock:^(ALAsset *asset)
{
result = [asset retain];
dispatch_async(dispatch_get_main_queue(), ^
{
[self loadPhotoImageViewWithAsset:result];
[self dismissModalViewControllerAnimated:YES];
[imageURL release];
[result release];
});
}
failureBlock:^(NSError *error)
{
}];
}
当我进入dispatch_async(dispatch_get_main_queue(), ^ block
时,result
显示为nil
。谁知道我在这里做错了什么?
答案 0 :(得分:2)
请参阅UIImagePickerController to use for a UIImageView,结果显示为nil。
像这样使用:
[self.assetsLibrary assetForURL:imageURL resultBlock:^(ALAsset *asset)
{
result = [asset retain];
[self loadPhotoImageViewWithAsset:result];
[self dismissModalViewControllerAnimated:YES];
[imageURL release];
[result release];
}
failureBlock:^(NSError *error)
{
}];
更改loadPhotoImageViewWithAsset
方法
-(void)loadPhotoImageViewWithAsset:(ALAsset *)asset
{
//dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
//dispatch_async(queue, ^{
dispatch_async(dispatch_get_main_queue(), ^
{
//here code for loading image
});
// });
}