I know I can use import {Linking} from 'react-native'
in order to use Linking.canOpenURL(url)
and open another app.
I can open PowerPoint by doing this: Linking.canOpenURL('ms-powerpoint://app')
but I need to open a file there.
According to Microsoft's Documentation I should be able to do this:
Linking.canOpenURL('ms-powerpoint:ofv|u|https://blablabla.com/file.pptx')
but the app tells me:
"Sorry, file.pptx is stored in an unsupported server location."
Another thing I thought was to first download the file and send the local path but, although it opens PowerPoint and shows a "Downloading/Opening" message, it shows like if it was a blank session.
Here's a small snippet of code:
import React from 'react';
import {Button, Linking} from 'react-native';
import RNFS, {DownloadFileOptions} from 'react-native-fs';
function ShowPPTComponent(props) {
function openFile() {
const {file} = props;
const temporalStoragePath = `${RNFS.DocumentDirectoryPath}/${file.name}.${file.extension}`;
const options = {
fromUrl: file.url,
toFile: temporalStoragePath,
};
// Downloads the file.
RNFS.downloadFile(options as DownloadFileOptions).promise.then(() => {
const url = `ms-powerpoint:ofv|u|${temporalStoragePath}`;
// Goes to PowerPoint
return Linking.openURL(url);
});
}
return (
<Button onPress={openFile} title="Open in PowerPoint" />
);
}
INFO PLIST
<key>LSApplicationQueriesSchemes</key>
<array>
<string>launch-ppt</string>
<string>powerpoint</string>
<string>ms-powerpoint</string>
<string>open-ppt</string>
</array>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
<key>UIFileSharingEnabled</key>
<true/>
<key>UISupportsDocumentBrowser</key>
<true/>
Notes:
In another place of the app I've shown the IOS Share options and I was able to select PowerPoint and open the file and it works perfectly. So both the file and the PowerPoint application are doing good.
(The idea here is to not show the IOS Share Modal but directly open PowerPoint with a file).
Thanks in advance !