当按下邮件button时,UIDocumentInteractionController委托方法不会被调用

我想显示警报消息当设备上没有邮件configuration。但是当我从文档交互单击邮件它只是简单地解雇控制器没有任何两个以下的委托方法将调用。请参阅图像更好的理解。

请帮忙。 提前致谢

- (void)openAppList:(FileInfo *)fileinfo { NSURL *fileURL = [NSURL fileURLWithPath:fileinfo.fullName]; UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL]; [interactionController retain]; interactionController.delegate = self; BOOL present = [interactionController presentOptionsMenuFromRect:CGRectZero inView:self.tabBarController.view animated:YES]; if (!present) { [MainteOrErrorDialog initWithErrorCode:kAlertNotOpenInFileId filename:fileInfo.filename target:nil action:nil]; } else { [interactionController retain]; } 

}

 #pragma UIDocumentInteractionDelegate - (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application { } - (void)documentInteractionController:(UIDocumentInteractionController *)controller didEndSendingToApplication:(NSString *)application { } 

在这里输入图像说明

不幸的是,你不能通过UIDocumentInteractionController与邮件委托进行真正的交互。 UIDocumentInteractionController是非常有限的,你可以用它所支持的所有应用程序的属性和属性来做什么,你甚至不能将邮件消息体设置为自定义消息。 实际上,在iOS 6.0中, documentInteractionController:canPerformAction:已被弃用,因为Apple正在向UIActivityViewController方向发展。 他们自己弃用的声明是:

应用程序应该使用UIActivityViewController进行操作


所以或者,用UIActivityViewController你可以。

解决这个问题,实现UIActivityViewController,他们都支持相同的应用程序,并检查用户是否可以发送电子邮件,如果没有,从菜单中排除邮件:

 if ([MFMailComposeViewController canSendMail]) { NSArray *shareItems; shareItems = @[[Config emailMessage], snapshot]; //emailMessage is an NSString containing the body of the mail or mms message located in a different VC UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:shareItems applicationActivities:nil]; [activityController setCompletionWithItemsHandler:(UIActivityViewControllerCompletionWithItemsHandler)^(NSString *string, BOOL completed) { } [self presentViewController:activityController animated:YES completion:nil]; } else { NSArray *shareItems; shareItems = @[[Config emailMessage], snapshot]; //emailMessage is an NSString containing the body of the mail or mms message located in a different VC UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:shareItems applicationActivities:nil]; activityController.excludedActivityTypes = @[UIActivityTypeMail]; [activityController setCompletionWithItemsHandler:(UIActivityViewControllerCompletionWithItemsHandler)^(NSString *string, BOOL completed) { } [self presentViewController:activityController animated:YES completion:nil]; }