我知道我可以使用import {Linking} from 'react-native'
来使用Linking.canOpenURL(url)
并打开另一个应用程序。
我可以通过执行以下操作打开 PowerPoint :Linking.canOpenURL('ms-powerpoint://app')
,但是我需要在其中打开文件。
根据Microsoft's Documentation,我应该可以这样做:
Linking.canOpenURL('ms-powerpoint:ofv|u|https://blablabla.com/file.pptx')
,但应用程序告诉我:
“ 很抱歉,file.pptx存储在不受支持的服务器位置。”
我想做的另一件事是首先下载文件并发送本地路径,但是,尽管它打开了PowerPoint并显示了“正在下载/正在打开”消息,但它似乎是空白会话。
这是一小段代码:
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" />
);
}
信息列表
<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/>
注意:
在该应用程序的另一个地方,我显示了IOS共享选项,并且能够选择PowerPoint并打开文件,它可以完美运行。因此,文件和PowerPoint应用程序都运行良好。
(这里的想法是不显示IOS共享模式,而是直接使用文件打开PowerPoint。)
提前谢谢!