【问题标题】:MFMailComposeViewController does not send mailMFMailComposeViewController 不发送邮件
【发布时间】:2011-03-24 16:04:52
【问题描述】:

我正在尝试使用 MFMailComposeViewController 发送邮件。一切正常,除了没有发送邮件,而且我总是收到 MFMailComposeResultFailed。

任何指针?我没有使用模拟器,并且可以从我的设备发送邮件。我确实有一个连接(通过 Reachability 进行测试),并且 [MFMailComposeViewController canSendMail] 返回 YES。

项目中没有编译器警告,没有崩溃...

【问题讨论】:

    标签: iphone email send mfmailcomposeviewcontroller


    【解决方案1】:

    这是 IOS4 中的一个错误。

    我的手机上有一个 Exchange 邮件帐户和一个旧的、不活动的 IMAP 帐户。显然,这会导致 iOS4 出现问题。邮件实际上被卡在发件箱中。删除非活动 IMAP 帐户后,一切都按预期进行。

    【讨论】:

    • 看起来这个bug在4.1中仍然存在。还不确定 4.2。
    【解决方案2】:

    有些读者可能会遇到这个问题:

    确保实现<MFMailComposeViewControllerDelegate> 协议

    代码如下:

    // in TestViewController.h
    @interface TestViewController : UIViewController<MFMailComposeViewControllerDelegate>
    @end
    
    // in TestViewController.m
    @interface TestViewController ()
    @end
    
    @implementation
    - (void) compose {
        MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
        picker.mailComposeDelegate = self;
    
        [picker setSubject:@"Hello there"];
    
        [picker setToRecipients:@[]];
    
        // Fill out the email body text
        NSString *emailBody = @"Hello, sending a message from my app";
    
        [picker setMessageBody:emailBody isHTML:NO];
    
        // use this function. presentModalViewController:... is deprecated
        [self presentViewController:picker animated:YES completion:nil];
    }
    
    - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
    {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    @end
    

    【讨论】:

      【解决方案3】:

      没有看到代码 sn-p 很难判断,但是您应该检查以下内容:

      1) 您已经正确设置了MFMailComposeViewController's 委托并实现了它的委托方法;

      2) 您已使用setSubject: 设置邮件主题

      3) 您已使用setMessageBody:isHTML: 设置消息正文

      并可选择使用addAttachmentData:mimeType:fileName:设置附加

      4) 您已经使用类似的方式向用户展示了您的邮件撰写视图控制器

      [self presentModalViewController:mcvc animated:YES];
      

      希望这会有所帮助。

      【讨论】:

      • 是的,我做的都是正确的。原来这是操作系统中的一个错误。请看下面我的回答。还是谢谢你:)
      猜你喜欢
      • 1970-01-01
      • 2012-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多