ios - 如何在iphone单独安装的应用程序中打开ppt、excel等文件?

标签 ios iphone xamarin xamarin.ios

我在 xamarin.ios 工作。在我的应用程序中,我需要显示一些文档,如 ppt、excel 等。我想在支持这些文件的设备中的单独安装的应用程序中打开这些文件。意味着如果我尝试打开一个 excel 文件,那么我可以获得所有支持打开该文件的已安装应用程序的列表,以及我选择的应用程序打开文档的列表。

如何在 xamarin.ios 中实现它?

最佳答案

你可以尝试使用UIDocumentInteractionController:

documentInteraction = new UIDocumentInteractionController();
documentInteraction.Url = new NSUrl(NSBundle.MainBundle.PathForResource("myExcel", "xlsx"), false);

documentInteraction.PresentOptionsMenu(sender.Bounds, sender, true);

确保将此 documentInteraction 作为属性保留。并且你要打开这个文件的第三方应用必须支持打开方式。

此外,您可以使用此 Controller 在应用内预览文件:

// Add a delegate
documentInteraction.Delegate = new MyDocumentDelegate(this);

public class MyDocumentDelegate : UIDocumentInteractionControllerDelegate
{
    UIViewController presentedViewController;

    public MyDocumentDelegate(UIViewController viewController)
    {
        presentedViewController = viewController;
    }

    public override UIViewController ViewControllerForPreview(UIDocumentInteractionController controller)
    {
        return presentedViewController;
    }
}

关于ios - 如何在iphone单独安装的应用程序中打开ppt、excel等文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50565844/

相关文章:

android - React native 应用程序在 IOS 13 版本设备中崩溃

ios - 放入操作队列时网络操作不再完成

iphone - iOS 上的 Core Text 和复制粘贴

iphone - Apple 推送通知服务器 - 反馈始终返回零元组

iphone - 如何缩小资源文件夹?

c# - 如何在单击按钮时发送远程通知? Xamarin.Android C#

c# - WebView 中的 WebGL 在 UNO 构建中不起作用,但在 Xamarin 构建中起作用

ios - 从 PHAsset 获取视频时如何检测视频是否为横向/纵向?

iphone - 捕捉 UINavigationController native 后退按钮操作

xamarin - 有没有办法通过Xamarin Forms应用程序显示 native iOS和Android忙碌指示器?