我正在构建一个应用程序,让用户在点击按钮时下载PDF文件。
为此,我使用库react-native-fetch-blob。
在Android上运行良好。
在iOS上,控制台日志告诉我下载效果不错,但是:
实现我想要的正确方法是什么?
答案 0 :(得分:0)
在iOS中为我工作的解决方案是在获取时使用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);
})
}