Search code examples
iphoneiosobjective-cipaduidocumentinteraction

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.


Solution

  • 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.