ios – UIDocumentInteractionController不显示邮件选项

前端之家收集整理的这篇文章主要介绍了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
@H_301_27@presentOptionsMenuFromBarButtonItem:animated: method,but presents a
menu restricted to a list of apps capable of @H_301_27@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];

猜你在找的iOS相关文章