UIDocumentInteractionController Does Not Show Mail Option
Asked Answered
S

1

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?

Sangsanger answered 28/4, 2014 at 8:41 Comment(6)
What type of file are you trying? Show us your fileURL code?Kylie
is the mail app available on your device ?Alexiaalexin
@Kylie 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.pdfSangsanger
@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.Sangsanger
Did you try changing the presentOptionsMenuFromRect to presentOpenInMenuFromRect:inView:animated?Kylie
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)Kylie
C
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];
Carleencarlen answered 28/4, 2014 at 11:5 Comment(2)
In your example, I think you mean: [docInteractionController presentOptionsMenuFromBarButtonItem:(UIBarButtonItem*)sender animated:YES];. As it is now, this won't compile or run.Jestinejesting
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?Eal

© 2022 - 2024 — McMap. All rights reserved.