我必须让用户在按下按钮时下载 pdf 文件,我发现我必须使用 rn-fetch-blob 而不是 react-native-fetch-blob。在文档中有这段代码:
const { config, fs } = RNFetchBlob
let DownloadDir = fs.dirs.DownloadDir // this is the Downloads directory.
let options = {
fileCache: true,
addAndroidDownloads : {
useDownloadManager : true, //uses the device's native download manager.
notification : true,
title : "Notification Title", // Title of download notification.
path: DownloadDir + "/me_"+ '.' + extension, // this is the path where your download file will be in
description : 'Downloading file.'
}
}
config(options)
.fetch('GET',"https://whatever_url_u _want/)
.then((res) => {
//console.log("Success");
})
.catch((err) => {console.log('error')}) // To execute when download cancelled and other errors
}
我不知道我能用这个做什么!如何在 TouchableOpacity onPress 道具中使用它?请有人可以提供一个详细的例子
PS。我使用 POST 方法调用 API,并收到 PDF 文件的链接。我认为
I have to set this link like that
config(options)
.fetch('GET',this.state.data.link)