【发布时间】:2013-11-04 21:29:15
【问题描述】:
好的,所以我设置了 ImagePicker 所有设置和 ALAssetLibrary 设置来获取图片和标题(如果现有图片存在或新图片的通用文本存在)但现在我想弄清楚是否有办法我可以通过assetForURL 方法在块调用之外访问此信息。所以这是我的代码,以便我可以显示正在发生的事情(这是在选择图片后显示的屏幕的 viewDidLoad 方法中)
__block NSString *documentName;
__block UIImage *docImage;
NSURL *resourceURL = [imageInfo objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *asset)
{
ALAssetRepresentation *imageRep = [asset defaultRepresentation];
//Get Image
CGImageRef iref = [imageRep fullResolutionImage];
//If image is null then it's a new picture from Camera
if (iref == NULL) {
docImage = [imageInfo objectForKey:UIImagePickerControllerOriginalImage];
documentName = @"New Picture";
}
else {
docImage = [UIImage imageWithCGImage:iref];
documentName = [imageRep filename];
}
};
// get the asset library and fetch the asset based on the ref url (pass in block above)
ALAssetsLibrary *imageAsset = [[ALAssetsLibrary alloc] init];
[imageAsset assetForURL:resourceURL resultBlock:resultblock failureBlock:nil];
现在我希望能够在此 ViewController 的其他地方使用这两个变量(documentName 和 docImage)(例如,如果有人想在保存文档之前更改文档的名称,我希望能够恢复到默认名称),但我似乎无法弄清楚我需要做什么,以便以后可以使用这些变量。不知道这是否有意义,所以如果我需要澄清其他任何事情,请告诉我。
【问题讨论】:
标签: uiimagepickercontroller alassetslibrary