Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if any apps are associated with file extension

I want to make "Open in.." function in my iOS application.

Is there any way to check if any app on this device is associated with file extension that i want to share?

If there are no apps on current device to open file with such an extension than UIDocumentInteractionController will not be displayed after clicking on "Open in.." button, but i want not to show this button in such case.

So the question is: how to check if any app on device can open some file with specific extension?


Update:

For example UIDocumentInteractionController has NSArray property icons.

It contains images of all aplications that can open the file with my extension. But if there are no applications it contans image of empty application.

So i can't check it using docInteractionController.icons.count == 0 for example. I am looking for other tricks.'

Thanks, in advance.

like image 741
B.S. Avatar asked Mar 14 '13 11:03

B.S.


2 Answers

Although UIDocumentInteractionController does not offer a way to discover in advance whether there are any applications that can handle a document, -presentOpenInMenuFromRect: will return a flag indicating whether there were any applications that could open a document. This requires you to have already set up and presented the controller, which is not optimal.

There is a workaround for this, a little hacky but is functional: Before you invoke the "real" interaction controller, create a dummy one using a dummy document, and present it from the rect of the window's bounds. This guarantees that it will "appear" offscreen, so your user won't see it. At that point, you have the flag returned from -present, and you can immediately dismiss the dummy controller, and the proceed to show your UI appropriately.

like image 195
Ben Zotto Avatar answered Oct 13 '22 00:10

Ben Zotto


On OSX, you can get a list of application bundle identifiers capable of handling a specific content type using LSCopyAllRoleHandlersForContentType. But on iOS, I don't think there is such a way.

If I find, I'll edit my answer.

Considering you are looking for other tricks, you can check if that one image in the icons array is the generic document icon.

If it is then you know that there is no app associated to handle that file type. But this approach will be OS version dependent as generic file icon may change.

like image 30
erkanyildiz Avatar answered Oct 13 '22 00:10

erkanyildiz