如何判断(编程)是否有任何注册的应用程序支持打开特定的文档types?

Apple UIDocumentInteractionController的文档presentOpenInMenuFromBarButtonItem:animated:方法指出:“如果没有注册的应用程序支持打开文档,则文档交互控制器不会显示菜单。 在我的应用程序中,我想要显示一个button当且仅当设备上有一个应用程序将打开它。 (我只想让buttonpopup一个菜单来打开文件;我不想要QuickLook,Copy或Print)。 就目前而言,如果button在那里,但没有注册可以打开相关文件的应用程序,则用户得到不理想的button的不满意的体验。

所以 – 我可以找出是否有任何/没有注册的应用程序,支持打开特定的文档types? 显然,UIDocumentInteractionController实例可以find这个。 有没有一个公共的API方式找出来?

好的,更多的研究揭示了一个用户frenchkiss-dev的stackoverflow有一个解决scheme – 源于比我更仔细地阅读文档和一些侧面思考。 我的代码如下,基于frenchkiss-dev的回答,位于ViewDidAppear方法中,如果打开然后closures打开的文件菜单(没有animation)显示没有应用程序可以处理打开文件,则禁用我的button。 这段代码的上下文是一个UIDocumentInteractionController已经在viewDidLoad中设置好了,可以通过[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]; } 
 //Connect up theOpenInBtn in IB @interface DocumentViewerViewController () { IBOutlet UIWebView *webView; NSURL *fileURL; NSData *fileOnline; UIDocumentInteractionController *dic; IBOutlet UIBarButtonItem *theOpenInBtn; } (void)viewDidLoad { [super viewDidLoad]; BOOL isAnAppToOpenURL = [dic presentOpenInMenuFromRect:CGRectZero inView:[self view] animated: NO]; [dic dismissMenuAnimated:NO]; if (!isAnAppToOpenURL) { // iOS think NO app is present on the device that // can open the URL set on the UIDocumentInteractionController [theOpenInBtn setEnabled:NO]; } }