ios/Objective C - UIDocumentInteractionController - 'Open In' method always returns NO

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");

Answers


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.


Need Your Help

How to create a radio button and see if it's checked?

c++ winapi

How to create a radio button and see if it's checked?

Add Class before slide open and remove class after slide close using slideToggle?

jquery slidetoggle

I'm using jQuery to slide a menu open and closed when a link is clicked which is working great. However, I'm trying to add a class when the link is clicked before the menu slides open then remove the

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.