反应本机获取 blob 不在 iOS 上下载图像

问题描述

我正在尝试使用 rn-fetch-blob 库下载图像,但没有从我的服务器下载。相同的代码适用于 android,但不适用于 iOS。我还使用相机胶卷将图像保存在图库中,但它抛出错误 Could not find image 。我做错了什么?

下载代码

   function DownloadImage(url,id){
    let imgurl = url;

    let newimguri = imgurl.lastIndexOf('/');
    let imageName = imgurl.substring(newimguri);
    let dirs = RNFetchBlob.fs.dirs;
    let path = Platform.OS === 'ios' ? dirs['DownloadDir'] + imageName : dirs.PictureDir + imageName;   
        RNFetchBlob.config({
          fileCache: true,appendExt: 'png',path: path,}).fetch("GET",imgurl).then(res => {
         CameraRoll.save(res.path()).then(()=>{
            }).catch((ex)=>{
                alert("Error="+ex);
            });
        }).catch(error=>{
            obj.loadingflag=false;
            alert(error);
        });
        
   }

解决方法

在 IOS 上遇到了同样的问题。 解决方案是你必须这样做

.then(resp => {
      // console.log(resp);
      if (Platform.OS === "ios") {
        RNFetchBlob.ios.openDocument(resp.data);
      }
    })

你可以参考我的回答stack overflow response