I'm working an expo project and I'm using expo-linking library to trigger an opening of a PDF file when the download is completed. I just discovered that the expo linking canOpenURL method returns a false value for the "file" path on an iOS device.
const openDocument = () => { const contentUri = await FileSystem.getContentUriAsync(fileUri); console.log("Content URI: ", contentUri); /* Content URI: file:///var/mobile/Containers/Data/Application/9BE65D63-4F83-4C78- A9B7-E268DC3073EA/Documents/Certificate.pdf */ if (await Linking.canOpenURL(contentUri)) { Linking.openURL(contentUri); }}
I went through the expo-linking docs to understand why this is happening and I found this:
On iOS, Linking.canOpenURL requires additional configuration to query other apps' linking schemes. You can use the expo.ios.infoPlist key in your app config (app.json, app.config.js) to specify a list of schemes your app needs to query.
If you don't specify this list, Linking.canOpenURL may return false regardless of whether the device has the app installed. Note that this configuration can only be tested in development builds because it requires native changes that will not be applied when testing in Expo Go.
So I updated my app.json file with the following:
{"expo": {"name": "app-name","slug": "app-name","version": "1.0.0","orientation": "portrait","icon": "./assets/icon.png","ios": {"supportsTablet": true,"infoPlist": {"LSApplicationQueriesSchemes": ["mailto","message","readdle-spark","airmail","ms-outlook","googlegmail","inbox-gmail","ymail","superhuman","yandexmail","fastmail","protonmail","file" ], }, },"android": {"adaptiveIcon": {"foregroundImage": "./assets/adaptive-icon.png","backgroundColor": "#ffffff" },"permissions": ["android.permission.CAMERA","android.permission.RECORD_AUDIO" ], },"plugins": ["react-native-email-link", ["react-native-vision-camera", {"cameraPermissionText": "We need access to your camera to scan products' barcodes.","enableCodeScanner": true } ],"expo-secure-store", }}
I added the file to the list in the infoPlist as recommended in the docs and built my app using development build. After build completion, the Linking.canOpenURL(contentUri) still returns false. I have spent hours trying to debug what could be happening and I'm still unable to find a headway. Any good pointer to why this is happening would be greatly appreciated. Thank you.