ios – UIDocumentInteractionController不显示邮件选项

继承我的应用程序中的UIDocuemtnInteractionController(不显示邮件选项)

这是Apples示例项目使用的那个

以下是各自的代码

我的应用程序

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

Apple示例项目

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:

按照Apple Docs on UIDocumentInteractionController

对于-presentOpenInMenuFromBarButtonItem:animated:它说:

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.

所以:

>要显示打开文件的选项,请使用-presentOpenInMenuFromBarButtonItem:
>要显示适用于该文件的所有可能选项,请使用-presentOptionsMenuFromBarButtonItem:或通用-presentOptionsMenuFromrect:

另外……对于任何文件,最好指定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];

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...