UIDocumentInteractionController不显示邮件选项

时间:2014-04-28 08:41:37

标签: ios ios7 uidocumentinteraction

来自我的应用程序的UIDocuemtnInteractionController(不显示邮件选项) enter image description here

这是Apples示例项目使用的那个 enter image description here

以下是各自的代码

我的申请

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];

我应该做什么来获取邮件选项?

1 个答案:

答案 0 :(得分:18)

要提供Mail选项,-presentOpenInMenuFromBarButtonItem:需要-presentOptionsMenuFromRect:

根据Apple Docs on UIDocumentInteractionController

对于-presentOpenInMenuFromBarButtonItem:animated:,它说:

  

这种方法类似于    presentOptionsMenuFromBarButtonItem:animated: 方法,但提出了一个   菜单仅限于能够打开当前的应用列表   文献。该确定基于文档类型(如   由UTI属性指示)和支持的文档类型   已安装的应用程序   ...
  如果没有支持打开文档的注册应用程序,则   文档交互控制器不显示菜单。

所以:

  1. 要显示打开文件的选项,请使用-presentOpenInMenuFromBarButtonItem:
  2. 要提供适用于该文件的所有可能选项,请使用-presentOptionsMenuFromBarButtonItem:或通用-presentOptionsMenuFromRect:

  3. 另外......对于任何文件,最好指定UTI类型:

    实施例

    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];