我使用ELCImagePickerController
获取图片的网址。我存储了该URL以供将来参考。
我使用以下网址获取该网址:
[dict valueForKey:UIImagePickerControllerReferenceURL];
现在问题出现在一段时间后用户从照片库中删除了该特定图像 我将使用URL访问该图像。 我的应用程序没有崩溃。
我尝试过使用NSUrl方法
[imagePath checkResourceIsReachableAndReturnError:&err]
我尝试了类似的事情:
-(BOOL)findImage:(NSURL*)path
{
dispatch_group_t group = dispatch_group_create();
dispatch_group_enter(group);
__block BOOL flag=YES;
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullScreenImage];
if (iref) {
flag=YES;
dispatch_group_leave(group);
}
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"cant get image - %@",[myerror localizedDescription]);
flag=NO;
};
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:path resultBlock:resultblock failureBlock:failureblock];
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
dispatch_release(group);
[assetslibrary release];
return flag;
}
示例网址:
assets-library://asset/asset.JPG?id=E862927E-E646-448A-9EB6-A7D48668B3DC&ext=JPG
但没有成功。
如何知道特定网址上的图片。
如果任何人可以帮助我,这将是值得注意的。
提前致谢。
答案 0 :(得分:1)
对于这种情况,您需要检查ALAssetRepresentation * rep = [myasset defaultRepresentation]为nil。
if(rep != nil){
//write your code..
}
答案 1 :(得分:1)
解决了 findImage 方法
中的更改问题-(BOOL)findImage:(NSURL*)path
{
dispatch_group_t group = dispatch_group_create();
dispatch_group_enter(group);
__block BOOL flag=YES;
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:path resultBlock:^(ALAsset *asset) {
if (asset==nil)
{
flag=NO;
}
else
{
flag=YES;
}
dispatch_group_leave(group);
} failureBlock:^(NSError *error){
NSLog(@"operation was not successfull!");
dispatch_group_leave(group);
}];
dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
dispatch_release(group);
[assetslibrary release];
return flag;
}