2
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error

NSString *eventResult = nil;

[self dismissModalViewControllerAnimated:YES];

switch (result) {

    case MFMailComposeResultSent:

            eventResult = @"Mail Sent Succesfully";
            break;

    case MFMailComposeResultSaved:

            eventResult = @"Saved into draft";
            break;
    case MFMailComposeResultCancelled:

            eventResult = @"Mail Canceled";
            break;
    case MFMailComposeResultFailed:

            NSLog(@"Mail Fail:%@",[error localizedDescription]);
            eventResult = @"Mail failed";
            break;
}
    //alert for show status of mail

UIAlertView *mailStatusAlert  = [[UIAlertView alloc]initWithTitle:@"Email Alert" message:eventResult delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[mailStatusAlert show];
[mailStatusAlert release]

我使用上面的代码来处理邮件状态,当 wifi 开启时它工作正常,但如果 wifi 关闭,错误不会像失败一样显示。但我需要那张支票。还有其他方法可以处理该错误吗?我可以禁用横向的mailcomposeviewcontroller 方向吗,因为我的应用程序只支持纵向。

4

2 回答 2

2

在官方文档中,在概述部分中,对此问题进行了解释:

这使您即使在用户没有网络访问权限的情况下(例如在飞行模式下)也可以生成电子邮件。此界面不提供验证电子邮件是否实际发送的方法。

因此,当您生成电子邮件时,无需担心您的互联网连接。

正如spider1983所提到的,值得使用Apple 或第三方的Reachability类检查您的互联网连接(最后一个与 ARC 和 GCD 兼容)

于 2012-12-28T12:26:27.350 回答
0
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];

if(controller){

   controller.mailComposeDelegate = self;
   [controller setSubject:@"My Subject"];
   [controller setMessageBody:@"Hello there." isHTML:NO]; 
   [self presentModalViewController:controller animated:YES];
   [controller release];
}else{
   // your mail address is not configure
}
于 2012-12-28T12:30:58.480 回答