How to say (programmatically) if there are / are not any registered applications that support the opening of a certain type of document?

Apple Documentation for UIDocumentInteractionController presentOpenInMenuFromBarButtonItem: animated method: "If there are no registered applications that support opening a document, the document interaction controller does not display a menu." In my application, I want to display a button if and only if there is an application on the device that will open it. (I want the button to open the menu to open the file, I do not want QuickLook, Copy or Print). Anyway, if there is a button, but there are no applications registered that can open the corresponding file, the user receives an unsatisfactory impression of the button that does nothing when pressed.

So - can I find out if there are any / not registered applications that support opening a certain type of document? Obviously, instances of the UIDocumentInteractionController can find this. Is there a public search API?

+6
source share
2 answers

OK, more research shows that the user stackoverflow frenchkiss-dev has a solution - obtained from reading more carefully than me, and some side thoughts. My code below, based on the response of frenchkiss-dev, is in the ViewDidAppear method and disabling my button when opening and closing the open file menu (without animation) shows that there are no applications that can handle opening a file. The context of this snippet is that the UIDocumentInteractionController is already configured in viewDidLoad and is accessible 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]; } 
+11
source
 //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]; } } 
+1
source

Source: https://habr.com/ru/post/889746/


All Articles