问题描述
我想在设备上未配置任何邮件时显示警报消息.但是,当我单击来自文档交互的邮件"时,它只是关闭了控制器,以下两个Delegate方法将不会调用.请参阅Image以获得更好的理解.
I want to show the Alert message When no mail is configured on the device.But when i click Mail from document interaction it just simply dismiss the controller none of the two following Delegate method will call.Please refer Image for better understanding.
请帮助.在此先感谢
- (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与Mail委托进行交互.UIDocumentInteractionController极其限于您可以使用其支持的所有应用程序的属性进行操作,甚至不能将邮件消息主体设置为自定义消息.实际上,在iOS 6.0中已不推荐使用 documentInteractionController:canPerformAction:
,因为苹果正朝着UIActivityViewController迈进.它们是自己已弃用的语句是:
Unfortunately, you can't really interact with the Mail delegates through UIDocumentInteractionController. UIDocumentInteractionController is extremely limited to what you can do with properties and attributes of all apps it supports, you can't even set a mails message body to a custom message. In fact, documentInteractionController:canPerformAction:
is deprecated in iOS 6.0 because Apple was moving towards UIActivityViewController. They're own deprecated statement is :
因此,也可以使用UIActivityViewController.
So alternatively, with UIActivityViewController you can.
要解决此问题,请实现UIActivityViewController,它们都支持相同的应用程序,并检查用户是否可以发送电子邮件,否则,请从菜单中排除邮件":
A work around for this, implement UIActivityViewController, they both support the same apps and check if a user can send emails, if not, exclude Mail from the menu :
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];
}
这篇关于按下邮件按钮时不调用UIDocumentInteractionController委托方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!