我试图将文件写入 RNFetchBlob.fs.dirs.DownloadDir 但它总是返回Error: Operation not allowed 。它在 android 版本 10 及更低版本中运行良好。但对于 11 和 12,它会显示错误。有谁知道在本地写文件的任何替代方法?
const pathToWrite = `${RNFetchBlob.fs.dirs.DownloadDir}/` + 'Barcode/' + barCodeNumber + '_' + moment().format("DD-MM-YYYY HH:mm:ss") + `.csv`;
// console.log(pathToWrite)
RNFetchBlob.fs
.writeFile(pathToWrite, csvString, 'utf8')
.then(() => {
Alert.alert(
"Downloaded!!",
"CSV File Downloaded Successfully!",
);
RNFetchBlob.android.addCompleteDownload({
title: `Barcode-Scan Data`,
description: 'Barcode-Scan Data',
mime: 'text/csv',
path: pathToWrite,
showNotification: true,
notification: true
})
this.deleteData()
this.getBarCodeCountDetails()
})
.catch(error => console.error(error));
}