7

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?

BangOperator
  • 4,377
  • 2
  • 24
  • 38
  • What type of file are you trying? Show us your fileURL code? – GenieWanted Apr 28 '14 at 08:43
  • is the mail app available on your device ? – KIDdAe Apr 28 '14 at 08:43
  • @GenieWanted Here is the description of file URL Printing description of fileURL: file:///Users/Name/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/A0DC474B-790F-47DD-9DAA-F1B85A161DDD/Documents/Download/Important%20News%20About%20Your%20Taxes.pdf – BangOperator Apr 28 '14 at 09:36
  • @KIDdAe, YES.... And both the above application(My application and Apple sample application) were running on the simulator. So I suppose if apple sample could show it, even my application was supposed to show it. – BangOperator Apr 28 '14 at 09:39
  • 1
    Did you try changing the presentOptionsMenuFromRect to presentOpenInMenuFromRect:inView:animated? – GenieWanted Apr 28 '14 at 11:28
  • 1
    Also, try using [docInteractionController presentPreviewAnimated:YES]; and see if that really makes an impact? I have this same line of code in my app and it does work (shows the mail app) – GenieWanted Apr 28 '14 at 11:34

1 Answers1

20

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];
Andrew Vyazovoy
  • 580
  • 4
  • 12
staticVoidMan
  • 19,275
  • 6
  • 69
  • 98
  • In your example, I think you mean: `[docInteractionController presentOptionsMenuFromBarButtonItem:(UIBarButtonItem*)sender animated:YES];`. As it is now, this won't compile or run. – Logan Aug 20 '14 at 15:36
  • I have a similar situation but I want to show the mail option too so I can't use presentOpenInMenuFromBarButtonItem. But presentOptionsMenuFromBarButtonItem does not work on iOS 8 (must be a bug). So what can I do? – Shwethascar Dec 03 '14 at 22:41