I'm trying to download a PDF file from my app when a button is clicked and open it immediately after the download completes. I'm using expo-file-system to save the downloaded file and I'm using expo-linking to trigger the opening of the file after it's downloaded for iOS device. I'm also using the expo-intent-launcher to trigger the opening of the file on an android device. This works perfectly for android but this doesn't work on iOS and I've been on this for hours. I'm unsure what I'm not doing right. My code snippets is shown below:
import * as FileSystem from "expo-file-system";import * as Linking from "expo-linking";import * as IntentLauncher from "expo-intent-launcher";import { Button } from "react-native"export default function PdfDocumentsScreen() { const { isAndroid } = useDevicePlatform(); const downloadPDF = async () => { try { const uri ="https://${name}.s3.amazonaws.com/${bucket_name}/Certificate1.pdf"; const fileUri = FileSystem.documentDirectory +"Certificate.pdf"; const downloadObject = FileSystem.createDownloadResumable(uri, fileUri); const response = await downloadObject.downloadAsync(); console.log(response); if (response?.status === 200) { openPDF(fileUri); } else { console.error("Failed to download the PDF"); } } catch (error) { console.error("Error downloading the PDF: ", error); } }; const openPDF = async (fileUri: string) => { try { const contentUri = await FileSystem.getContentUriAsync(fileUri); console.log("Content URI: ", contentUri); if (!isAndroid) { if (await Linking.canOpenURL(contentUri)) { Linking.openURL(contentUri); } } else { IntentLauncher.startActivityAsync("android.intent.action.VIEW", { data: contentUri, flags: 1, }); } } catch (error) { console.error("Error opening the PDF: ", error); } }; return (<Button title="Download PDF" onPress={downloadPDF} /> )}