当我选择图像时,我正在使用资源库获取图像名称。
这是我的下面代码:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
UIImage *img=info[UIImagePickerControllerOriginalImage];
NSURL *refURL = [info valueForKey:UIImagePickerControllerReferenceURL];
// define the block to call when we get the asset based on the url (below)
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset)
{
NSString *filename;
ALAssetRepresentation *imageRep = [imageAsset defaultRepresentation];
NSLog(@"[imageRep filename] : %@", [imageRep filename]);
filename=[imageRep filename];
};
// get the asset library and fetch the asset based on the ref url (pass in block above)
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:refURL resultBlock:resultblock failureBlock:nil];
link=info[UIImagePickerControllerReferenceURL];
[picker dismissViewControllerAnimated:YES completion:nil];
}
内部文件名我有所选的照片名称,如 filename =“IMG_0001.JPG”;
现在我的问题是使用文件名可以从库中获取照片。
朋友建议我一个方法,教程等...
我已经搜索但最终无法到达我来到这里。
答案 0 :(得分:2)
不,不仅仅是名字。完整资产URL可用于检索照片(假设它仍然存在于设备上),但没有API可根据名称搜索资产。