UIDocumentInteractionController不显示邮件选项

inheritance自我的应用程序的UIDocuemtnInteractionController(不显示邮件选项) 在这里输入图像说明

这里是苹果示例项目使用的一个 在这里输入图像说明

这里是各自的代码

我的应用程序

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

苹果示例项目

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

我应该如何获得邮件选项?

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

根据UIDocumentInteractionController上的Apple Docs

-presentOpenInMenuFromBarButtonItem:animated:它说:

此方法类似于presentOptionsMenuFromBarButtonItem:animated:方法,但提供了一个菜单,限制在可以打开当前文档的应用程序列表中。 该确定基于文档types(由UTI属性指示)以及所安装的应用所支持的文档types。

如果没有支持打开文档的注册应用程序,则文档交互控制器不显示菜单。

所以:

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

另外…对于任何文件,最好指定UTItypes:

例:

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