按下邮件按钮时不调用UIDocumentInteractionController委托方法 [英] UIDocumentInteractionController delegate method do not called when pressed on mail button

查看:55
本文介绍了按下邮件按钮时不调用UIDocumentInteractionController委托方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在设备上未配置任何邮件时显示警报消息.但是,当我单击来自文档交互的邮件"时,它只是关闭了控制器,以下两个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进行操作

Apps should use UIActivityViewController for actions


因此,也可以使用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委托方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆