如何(以编程方式)告知是否有任何支持打开特定文档类型的注册应用程序? [英] How to tell (programmatically) if there are / are not any registered apps that support opening a specific document type?

查看:164
本文介绍了如何(以编程方式)告知是否有任何支持打开特定文档类型的注册应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple的UIDocumentInteractionController文档presentOpenInMenuFromBarButtonItem:animated:方法声明如果没有支持打开文档的注册应用程序,文档交互控制器不会显示菜单。在我的应用中,我想显示一个按钮当且仅当设备上有应用程序打开它时。 (我只希望按钮弹出一个菜单来打开文件;我不想要QuickLook,复制或打印)。事实上,如果按钮在那里,但没有注册可以打开相关文件的应用程序,则用户会在按下时无法获得无效的按钮体验。

Apple's documentation for UIDocumentInteractionController presentOpenInMenuFromBarButtonItem:animated: method states that "If there are no registered apps that support opening the document, the document interaction controller does not display a menu." In my app I want to display a button if and only if there is an app on the device that will open it. (I only want the button to pop up a menu to open a file; I don't want QuickLook, Copy or Print). As things stand, if the button is there, but no apps are registered that can open the relevant file, the user gets the unsatisfactory experience of a button that does nothing when tapped.

那么 - 我能否知道是否有任何/不支持打开特定文档类型的注册应用程序?显然,UIDocumentInteractionController实例可以找到它。是否有公共API方法可以找到它?

So - can I find out whether or not there are any / no registered apps that support opening a specific document type? Clearly, UIDocumentInteractionController instances can find this out. Is there a public API way of finding it out?

推荐答案

好的,更多研究揭示了stackoverflow用户 frenchkiss-dev - 源于比我更仔细地阅读文档和一些横向思维。我的代码基于frenchkiss-dev的答案,位于ViewDidAppear方法中,如果打开然后关闭打开的文件菜单(没有动画)则会禁用我的按钮,这表明没有可以处理打开文件的应用程序。此代码段的上下文是已在viewDidLoad中设置了UIDocumentInteractionController,并通过[self docInteractionController]进行访问。

OK, more research reveals a stackoverflow user frenchkiss-dev has a solution - derived from reading the docs more carefully than me and some lateral thinking. My code below, based on frenchkiss-dev's answer, sits in a ViewDidAppear method and disables my button if opening and then closing the open file menu (without animation) reveals that there are no apps that can handle opening the file. The context for this snippet is that a UIDocumentInteractionController has already been set up in viewDidLoad and is accessed via [self docInteractionController].

BOOL isAnAppToOpenURL = [[self docInteractionController] presentOpenInMenuFromRect:CGRectZero inView:[self view] animated: NO];
[[self docInteractionController] dismissMenuAnimated:NO];

if (!isAnAppToOpenURL)
{
    // iOS think NO app is present on the device that
    // can open the URL set on the UIDocumentInteractionController
    [[self openFileButton] setEnabled:NO];
}

这篇关于如何(以编程方式)告知是否有任何支持打开特定文档类型的注册应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆