MFMailComposeViewController - iPad [英] MFMailComposeViewController - iPad

查看:139
本文介绍了MFMailComposeViewController - iPad的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一个MFMailComposeViewController,它在iPhone上运行得很好,但在iPad上崩溃,说:

I've setup a MFMailComposeViewController and it works just fine on the iPhone, but on the iPad it crashes, saying:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target...

那为什么会创建一个零模态视图?

So why would this create a nil modal view?

    MFMailComposeViewController *message = [[MFMailComposeViewController alloc] init];
    [message setMessageBody:@"My message here"  isHTML:NO];
    [message setToRecipients:[NSArray arrayWithObject:@"my@domain.com"]];
    [message setSubject:@"Request Info"];
    message.mailComposeDelegate = self;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        message.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentModalViewController:message animated:YES];
    [message release];

任何想法?

推荐答案

这样的LoX由于某种原因没有创建MFMailComposeViewController 因此具有 nil 值。在呈现之前检查它是否为零(虽然此解决方法不能解决此处出现的问题...)。

Loos like MFMailComposeViewController was not created for some reason and thus has nil value. Check if it is nil before presenting it (although this workaround does not answer what went wrong here...).

如果邮件编辑器可以发送,您还应该执行检查在尝试使用 + canSendMail 方法创建并呈现它之前的邮件(例如,如果设备上没有设置邮件帐户,则会返回NO):

You should also perform the check if mail composer can send mail before trying to create and present it using +canSendMail method (it will return NO for example if no mail account set up on device):

 if ([MFMailComposeViewController canSendMail]){
    // Create and show composer
 }
 else{
   // Show some error message here
 }

这篇关于MFMailComposeViewController - iPad的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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