ios - RN 从 IOS 中的 URL 获取 blob 下载 docx 或 pdf

标签 ios react-native rn-fetch-blob

做了什么 :

在Android中实现并在特定的DCIM directory中下载在安卓中。
在 ios 中使用 DocumentDir下载pdf或docx文件。使用 "rn-fetch-blob": "^0.12.0" ;

错误 :

在 IOS 中,它在控制台中显示消息:

The file saved to /var/mobile/Containers/Data/Application/E6FDC2DD-7FCA-44DC-85C4-A275078F8825/Documents/wow13.pdf



要下载的代码是这样的:
downloadFileOnSuccess = async () => {
    let dirs =
      Platform.OS == 'ios'
        ? RNFetchBlob.fs.dirs.DocumentDir
        : RNFetchBlob.fs.dirs.DCIMDir;
    console.log(dirs, 'document path');
    RNFetchBlob.config({
      // response data will be saved to this path if it has access right.

      fileCache: true,
      path: dirs + `/wow13.pdf`,
    })
      .fetch(
        'GET',
        'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf',
        {
          //some headers ..
        },
      )
      .then(res => {
        // the path should be dirs.DocumentDir + 'path-to-file.anything'
        console.log('The file saved to ', res.path());
      });
  };

但我无法在我的 iphone 7 真机中下载文件。我在 IOS 中缺少任何权限吗?尚未为 IOS 添加任何权限。

最佳答案

感谢 pruthvi,我得到了答案,对于 ios,我需要提示用户:

.then(resp => {
      if (Platform.OS === "ios") {
        RNFetchBlob.ios.openDocument(resp.data);
      }
    })
希望对你们有帮助

关于ios - RN 从 IOS 中的 URL 获取 blob 下载 docx 或 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60052019/

相关文章:

ios - 下载图像无法在 IOS 设备上运行 - React Native

javascript - RN-fetch-blob 错误 base64 - 仅限 android 问题

ios - 为什么我的新应用会覆盖我的开发设备上的旧版本,我如何才能将它们分开?

ios - Xcode 在模拟器名称旁边显示奇怪的数字

ios - 如何使用 UserDefaults 快速实现登录/注销导航?

javascript - 有没有办法在react-navigation(react-native)中保存和恢复导航历史记录

react-native - React Native - react 原生架构

iphone - 创建自定义 slider 的方法

android - React-Native Module HMRClient 不是注册的可调用模块(调用启用)

android - 如何在React-native中将图像从图库复制到应用程序的安装目录