I am using UIDocumentInteractionController for showing popover menu \"Open In...\" so that user can open a document in other application.
Method p
I came up with a less hacky way of doing things, but there is a limitation that you can only detect whether there's a compatible app after the user has selected to open in an app. This will enable you to provide the same user experience as the Dropbox app.
All you need to do is set up the UIDocumentInteractionControllerDelegate and create a boolean flag property that holds whether or not the menu was presented.
In the interface:
/**
The document interaction controller used to present the 'Open with' dialogue.
*/
@property (nonatomic,strong) UIDocumentInteractionController *documentInteractionController;
/**
Boolen that holds whether or not there are apps installed that can open the URL.
*/
@property (nonatomic) BOOL hasCompatibleApps;
In the implementation:
- (void)shareFileAtURL:(NSURL*)fileURL
{
[self setDocumentInteractionController:[UIDocumentInteractionController interactionControllerWithURL:fileURL]];
[[self documentInteractionController] setDelegate:self];
[self setHasCompatibleApps:NO];
[[self documentInteractionController] presentOpenInMenuFromRect:[self popoverRect] inView:[self popoverView] animated:YES];
if (![self hasCompatibleApps])
{
// Show an error message to the user.
}
}
#pragma mark - UIDocumentInteractionControllerDelegate methods
- (void)documentInteractionControllerWillPresentOpenInMenu:(UIDocumentInteractionController *)controller
{
[self setHasCompatibleApps:YES];
}
I hope that helps some people.