Check if there is an application that can open the file before calling presentOpenInMenuFromRect

I saved the file (pdf) in the "documents" directory, and I would like to know how it is possible to detect whether applications (applications) are installed on the mobile device that can open this file (for example, "pdf" files can be opened using "iBooks "," DropBox ", ...). I would like to detect this before calling the "presentOpenInMenuFromRect" method; which shows a list of possible applications that can process a specific file. Desired behavior:

1). Given the pdf file stored in the Document directory, check if the iPhone / iPad application has an “application” that can open this file (iBooks, DropBox, ...). This is what I do not know how to do it.

2) If the iPhone / iPad application cannot open the application, then do nothing, otherwise draw the "Save" button, and then, if the user clicks the "Save" button, then the "presentOpenInMenuFromRect" method will show a list of possible applications that can open this file. I know a way to present a list of applications that can open a file; here is the source code:

Source code associated with the Save button:

- (void) saveFile:(UIWebView*)webView { NSString* fileName = [[NSFileManager defaultManager] displayNameAtPath:webView.request.URL.absoluteString]; #if DEBUG NSLog(@"<%p %@: %s line:%d> File name:%@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __PRETTY_FUNCTION__, __LINE__, fileName); #endif NSURL* fileurl = [NSURL URLWithString:webView.request.URL.absoluteString]; NSData* data = [NSData dataWithContentsOfURL:fileurl]; NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString* docsDirectory = [paths objectAtIndex:0]; NSString* filePath = [docsDirectory stringByAppendingPathComponent:fileName]; [data writeToFile:filePath atomically:YES]; NSURL* url = [NSURL fileURLWithPath:filePath]; //UIDocInteractionController API gets the list of devices that support the file type docController = [UIDocumentInteractionController interactionControllerWithURL:url]; [docController retain]; //Very important, if "retain" is not called, the application crashes //Present a drop down list of the apps that support the file type, //clicking on an item in the list will open that app while passing in the file. BOOL isValid = [docController presentOpenInMenuFromRect:CGRectZero inView:webView animated:YES]; //Using "webView" instead of "self.view" if (!isValid) { [self showAlertSaveFileError:fileName]; //Shows an alert message } } 

Thanks in advance.

Note. The response time of the call to the presentOpenInMenuFromRect method is about a few seconds, so I want to know if there is another way to detect and get a list of possible applications installed on a mobile device that can open a specific file (pdf, ...)

+4
source share
1 answer

Check out ihasapp.

http://www.ihasapp.com/ he says it’s an iOS infrastructure that allows developers to discover applications that are currently installed on their users ’devices.

+1
source

All Articles