我在 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/