0

!help : 从 url 下载和预览/保存设备 pdf 在 react native for iOS 中不起作用。已经尝试过来自 stackoverflow 和 RN-fetch-blob 的不同帖子,但没有一个有效!

    const { config, fs } = RNFetchBlob;
    let DownloadDir = Platform.OS === 'android' ? fs.dirs.DownloadDir : fs.dirs.DocumentDir;
    console.log(DownloadDir)
    let array = url.split('/');
    let count = array.length
    console.log(array[count - 1])
    var Dated = new Date(); 
    const configfb = {
      fileCache: true,
      useDownloadManager: true,
      notification: true,
      mediaScannable: true,
      title: array[count - 1].pdf,
      path: DownloadDir +
      array[count - 1]+ '.pdf',
    }
    let date = new Date();
    let options = {
      fileCache: true,
      addAndroidDownloads: {
        //Related to the Android only
        useDownloadManager: true,
        notification: true,
        path:
        DownloadDir +
          Math.floor(date.getTime() + date.getSeconds() / 2) + '.pdf',
        description: 'PDF Download',
      },
    };
    config(options)
      .fetch('GET', url)
      .then((res) => {
        //Showing alert after successful downloading
        console.log('res -> ', JSON.stringify(res));
        console.log(res.path)
        //alert('Pdf Downloaded Successfully.');
        if (Platform.OS === 'android') { RNFetchBlob.android.actionViewIntent(res.path(), 'application/pdf') }
        else {
          RNFetchBlob.fs.writeFile(configfb.path, res.data, 'base64');
          RNFetchBlob.ios.previewDocument(configfb.path);
        }
      });
  } ```
4

0 回答 0