有没有可能使用文件名从库中获取照片?

There is any possibility to get the photo from library using filename?

每当我选择图像时,我都会使用资产库获取图像名称。

这是我的以下代码:

-(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";

现在我的问题是使用文件名我可以从库中获取照片吗?

朋友给我建议方法、教程等...

找遍了还是找不到终于来了

不,不是单从名字。完整的资产 URL 可用于检索照片(假设它仍然存在于设备上)但没有 API 根据名称搜索资产。