我正在尝试使用 MFMailComposeViewController 发送邮件。一切正常,除了没有发送邮件,而且我总是收到 MFMailComposeResultFailed。
任何指针?我没有使用模拟器,并且可以从我的设备发送邮件。我确实有一个连接(通过 Reachability 进行测试),并且 [MFMailComposeViewController canSendMail] 返回 YES。
项目中没有编译器警告,没有崩溃......
我正在尝试使用 MFMailComposeViewController 发送邮件。一切正常,除了没有发送邮件,而且我总是收到 MFMailComposeResultFailed。
任何指针?我没有使用模拟器,并且可以从我的设备发送邮件。我确实有一个连接(通过 Reachability 进行测试),并且 [MFMailComposeViewController canSendMail] 返回 YES。
项目中没有编译器警告,没有崩溃......
这是IOS4中的一个错误。
我的手机上有一个 Exchange 邮件帐户和一个旧的、非活动的 IMAP 帐户。显然,这会导致 iOS4 出现问题。邮件实际上被卡在发件箱中。一旦我删除了不活动的 IMAP 帐户,一切都按预期工作。
有些读者可能会遇到这个问题:
确保你实现了<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
没有看到代码片段就很难判断,但是您应该检查以下内容:
1)您已正确设置MFMailComposeViewController's
委托并实现其委托方法;
2)您已使用设置邮件主题setSubject:
3)您已使用设置消息正文setMessageBody:isHTML:
并可选择使用设置附加addAttachmentData:mimeType:fileName:
4)您已经使用类似的东西向用户展示了您的邮件撰写视图控制器
[self presentModalViewController:mcvc animated:YES];
希望这可以帮助。