如何检查UIDocumentInteractionController是否因iPad上缺少外部应用程序而无法打开文档? [英] How to check if UIDocumentInteractionController will fail to open document due to missing external application on iPad?

查看:375
本文介绍了如何检查UIDocumentInteractionController是否因iPad上缺少外部应用程序而无法打开文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 UIDocumentInteractionController 来显示弹出式菜单Open In ...,以便用户可以在其他应用程序中打开文档。

I am using UIDocumentInteractionController for showing popover menu "Open In..." so that user can open a document in other application.

方法 presentOpenInMenuFromBarButtonItem:animated:返回如果没有应用程序能够打开给定文件(菜单不会显示)。但是我等到目前为止已经为时已晚。我想禁用启动该按钮的按钮,如果不可能而不是提高用户的期望然后说对不起,则无法打开它。

Method presentOpenInMenuFromBarButtonItem:animated: returns NO in case there is no application able to open given document (menu will not show). But it is too late for me to wait until getting so far. I would like to disable the button initiating that opening if it is not possible instead of raising expectations of an user and then say "sorry, it is not possible to open it".

是否可以查询系统以查看是否至少有一个应用程序已注册特定文档类型?我已检查 canPreviewItem: QLPreviewController 中,但它似乎不支持 UIDocumentInteractionController 可以处理。

Is it possible to query system to see if there is at least one application registered for particular document type? I have checked canPreviewItem: in QLPreviewController, but it seems it doesn't support the same document types which UIDocumentInteractionController can handle.

推荐答案

不适用于iOS 6.0(见评论)

似乎dismissMenuAnimated(根本没有动画)是关键:

It seems that dismissMenuAnimated (with no animation at all) is the key:

-(BOOL)canOpenDocumentWithURL:(NSURL*)url inView:(UIView*)view {
    BOOL canOpen = NO;
    UIDocumentInteractionController* docController = [UIDocumentInteractionController 
                                                   interactionControllerWithURL:url];
    if (docController)
    {
        docController.delegate = self;
        canOpen = [docController presentOpenInMenuFromRect:CGRectZero
                                   inView:self.view animated:NO];                   
        [docController dismissMenuAnimated:NO];
    }
    return canOpen;
}

如果至少有一个应用程序能够打开指向的文件,它将返回YES通过网址。
至少它在我的情况下工作(KMZ文件),在iPhone iOS 4.3上使用/不使用Dropbox应用程序进行测试。

实际上,即使url没有指向实际文件,它似乎也能正常工作(即@test.kmz),但我不会依赖它来处理所有文件类型。

It will return YES if at least one application is able to open the file pointed by url. At least it's working in my case (KMZ files), testing with/without Dropbox app on iPhone iOS 4.3.
Actually, it seems to work even if url is not pointing to an actual file (i.e. @"test.kmz"), but I wouldn't rely on it for all file types.

这篇关于如何检查UIDocumentInteractionController是否因iPad上缺少外部应用程序而无法打开文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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