Arn*_*aud 5 ios react-native react-native-ios react-native-fetch-blob
我正在构建一个应用程序,让用户在单击按钮时下载 PDF 文件。
为此,我使用了库 react-native-fetch-blob。
它在 Android 上运行良好。
在 iOS 上,控制台日志告诉我下载运行良好,但是:
实现我想要的目标的正确方法是什么?
在 iOS 中对我有用的解决方案是在 fetch 的 then 中使用 RNFetchBlob.ios.openDocument 函数。此功能在设备文件资源管理器上打开文件,您可以在其中选择下载。这是代码示例:
downloadPDFiOS (uri) {
let uriSplitted = uri.split("/");
const fileName = uriSplitted.pop();
const dirs = RNFetchBlob.fs.dirs;
RNFetchBlob
.config({
path: dirs.DocumentDir + '/' + fileName,
fileCache: true,
})
.fetch('GET', uri, {
//some headers ..
})
.then((res) => {
RNFetchBlob.ios.openDocument(res.data);
})
.catch((e) => {
console.log('Error en el fetch: ', e);
})
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2094 次 |
| 最近记录: |