这是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];
我应该怎样做才能获得邮件选项?
解决方法
按照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];