Question

Heres the UIDocuemtnInteractionController from my application(does not show mail option) enter image description here

Here the one that Apples sample project uses enter image description here

Here are the respective codes

My application

docInteractionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
[docInteractionController presentOpenInMenuFromBarButtonItem:(UIBarButtonItem*)sender animated:YES];

Apple Sample Project

NSURL *fileURL;
if (cellIndexPath.section == 0)
{
    // for section 0, we preview the docs built into our app
    fileURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:documents[cellIndexPath.row] ofType:nil]];
}
else
{
    // for secton 1, we preview the docs found in the Documents folder
    fileURL = [self.documentURLs objectAtIndex:cellIndexPath.row];
}
self.docInteractionController.URL = fileURL;

[self.docInteractionController presentOptionsMenuFromRect:longPressGesture.view.frame
                                                   inView:longPressGesture.view
                                                 animated:YES];

WHAT SHOULD I DO TO GET THE MAIL OPTION?

Was it helpful?

Solution

To provide the Mail option, -presentOpenInMenuFromBarButtonItem: needs to be -presentOptionsMenuFromRect:

As per the Apple Docs on UIDocumentInteractionController

For -presentOpenInMenuFromBarButtonItem:animated: it says:

This method is similar to the presentOptionsMenuFromBarButtonItem:animated: method, but presents a menu restricted to a list of apps capable of opening the current document. This determination is made based on the document type (as indicated by the UTI property) and on the document types supported by the installed apps.
...
If there are no registered apps that support opening the document, the document interaction controller does not display a menu.

So:

  1. To present options to open the file, use -presentOpenInMenuFromBarButtonItem:
  2. To present all possible options applicable on the file, use -presentOptionsMenuFromBarButtonItem: or the generic -presentOptionsMenuFromRect:

Also... for any file, it would be better to specify the UTI type:

Example:

docInteractionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
//[docInteractionController setDelegate:self];
[docInteractionController setUTI:@"public.data"];
[docInteractionController presentOptionsMenuFromBarButtonItem:(UIBarButtonItem*)sender 
                                                animated:YES];
//or a generic method
//[docInteractionController presentOptionsMenuFromRect:sender.frame
//                                            animated:YES];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top