Question

I'm hoping someone can help with a very frustrating issue I'm having with the UIDocumentInteractionController.

I need to invoke the 'presentOpenInMenuFromRect' method, to allow the user to open a file in another app. At this stage I'm simply doing a proof of concept, so am just using a very basic file type for testing purposes.

I've set up my UiDocumentInteractionController using the code below, and have verified that the filepath URL is correct, as I can successfully call the presentPreviewAnimated method, and the document does indeed open fine in preview mode.

The problem I have is that the 'presentOpenInMenuFromRect' always returns NO, regardless of what file type I use. So far, I have used the following common file types, all to no avail: jpg, png, pdf, txt, rtf and html.

I'd be grateful for any advice, if anyone has run into this problem. Surely at least one of these files should be recognized by the device as having an associated app (and does the fact that it previews OK not in fact prove this?) I wonder id I'm doing something more fundamentally wrong? I'm debugging on the iPhone btw, so this isn't a quirk of the simulator.

Any advice would be very, very welcome! Thanks in advance.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSURL *filePath = [NSURL fileURLWithPath:[documentsDirectory stringByAppendingPathComponent:@"test.txt"]];

documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:filePath];
documentInteractionController.delegate = self;
[documentInteractionController retain];

// The following line does work, so we know the UIDocumentInteractionController and filepath are fundamentally correct
// [documentInteractionController presentPreviewAnimated:YES];

// Method ALWAYS returns NO, no matter what file type is used
if (![documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES])
    NSLog(@"Failed to show Open In menu");
Was it helpful?

Solution

Just thought I'd post an update on this for anyone else having the same issue...I now believe the reason the 'Open In' menu is not appearing was due to the simple fact that there were no apps installed with the file extensions I'd used.

This seems fairly obvious now, but at the time I'd assumed that some of the more common file types would be associated with system apps etc - however upon installing Adobe Reader, this now seems to work with pdf's.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top