首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MFMailComposeViewController - iPad

MFMailComposeViewController - iPad
EN

Stack Overflow用户
提问于 2011-02-14 07:45:52
回答 5查看 12.6K关注 0票数 31

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

代码语言:javascript
复制
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target...

那么为什么这会创建一个nil模式视图呢?

代码语言:javascript
复制
    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];

有什么想法吗?

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2011-02-14 08:18:59

MFMailComposeViewController这样的nil不是出于某种原因而创建的,因此具有Loo的价值。在演示之前检查它是否为nil (尽管此解决方法不能回答此处出现问题的原因...)。

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

代码语言:javascript
复制
 if ([MFMailComposeViewController canSendMail]){
    // Create and show composer
 }
 else{
   // Show some error message here
 }
票数 73
EN

Stack Overflow用户

发布于 2011-02-18 21:07:27

在创建MFMailComposerViewController对象之前,您必须放入check canSendMail,查看来自MFMailComposeViewController.h类的以下注释:

代码语言:javascript
复制
/*!
@method     canSendMail
@abstract   Returns <tt>YES</tt> if the user has set up the device for sending email.
@discussion The client may continue to set the recipients and content if the return value was <tt>YES</tt>.  If <tt>NO</tt>
            was the result, the client has a couple options.  It may choose to simply notify the user of the inability to
            send mail, or it may issue a "mailto" URL via <tt>-[UIApplication openURL:]</tt>.
*/

+ (BOOL)canSendMail __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);

在您的设备设置为发送邮件之前,您的对象不会被初始化。

票数 11
EN

Stack Overflow用户

发布于 2013-06-29 17:58:25

代码语言:javascript
复制
if ([MFMailComposeViewController   canSendMail]){
    //execute  your    code 
else{
    UIAlertView *anAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No mail account setup on device" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];     
    [anAlert addButtonWithTitle:@"OK"];
    [anAlert show];
}

如果您收到警报,请在手机上配置您的邮件帐户。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4987703

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档