I have implemented method to download images list as pdf to mobile storage, android works fine without any issues but ios not working. I give all the necessary permission for both OS, but iOS not working.
const downloadAndSavePDFs = async () => {
setDownloadingToDevice(true);
const externalStorageDirectory =
Platform.OS === 'android'
? RNFS.DownloadDirectoryPath
: RNFS.DocumentDirectoryPath;
const imageArray = downloadImages.map((item: any) => item.image);
const pdfContent = imageArray
.map((base64Image: any) => `<img src=${base64Image} />`)
.join('');
const htmlContent = `
<!doctype html>
<html>
<body>
<div class="header">
<h3>${
toggleCheckBox
? t('10017') && t('10017') !== '10017'
? t('10017') + ': ' + voucher.archiveNo
: 'Archive number: ' + voucher.archiveNo
: ''
}</h3>
</div>
<div class="pdf-content">
${pdfContent}
</div>
</body>
</html>
`;
const options = {
html: htmlContent,
fileName:
voucher.clientID.toString() + ' - ' + voucher.archiveNo.toString(),
directory: 'Documents',
};
const pdfFile: any = await RNHTMLtoPDF.convert(options);
const downloadsPath = `${externalStorageDirectory}/${
voucher.clientID + ' - ' + voucher.archiveNo
}.pdf`;
try {
Platform.OS === 'android' &&
(await RNFS.moveFile(pdfFile.filePath, downloadsPath));
setDownloadingToDevice(false);
} catch (error) {
console.log(error);
setDownloadingToDevice(false);
}
Can someone help me sort out this issue ?
Verify that the file paths you used to move and save the PDF file are appropriate for iOS. While 'Documents' is the location you are using, on iOS it may need to be something like 'Library/Caches' or another suitable directory. See the RNFS documentation for pathways unique to iOS.
To handle file paths differently depending on the platform, use conditional statements.
Adjust the way you handle errors to record comprehensive details about any problems that arise when transferring files. This can assist you in determining the precise problem.
Use RNFS.MainBundlePath for Reading: If you are reading a PDF file from the main bundle, you might want to use RNFS.MainBundlePath as the source path rather than pdfFile.filePath.
Ensure that your app has the necessary permissions to perform file operations on iOS. Check the iOS-specific permissions and make sure you have the appropriate entries in your app's Info.plist file.