首页 > 解决方案 > 在 React Native (IOS) 的 PowerPoint 应用程序中打开一个 .ppt 文件

问题描述

我知道我可以使用import {Linking} from 'react-native'以使用Linking.canOpenURL(url)和打开另一个应用程序。

我可以通过这样做打开PowerPointLinking.canOpenURL('ms-powerpoint://app') :但我需要在那里打开一个文件。

根据微软的文档,我应该能够做到这一点:

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)。

提前致谢 !

标签: iosreact-nativepowerpointreact-native-fs

解决方案


推荐阅读