这是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
@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:
例:
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];