当wifi关闭并且未显示错误时,邮件未发送

时间:2012-12-28 12:10:34

标签: ios wifi mfmailcomposeviewcontroller

-(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关闭错误不显示像faile。但我需要检查。有没有其他方法来处理该错误?并且我可以禁用mailcomposeviewcontroller方向的横向,因为我的应用程序仅支持肖像。

2 个答案:

答案 0 :(得分:2)

从官方doc开始,在概述一节中,就此问题提供了解释:

  

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

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

正如 spider1983 所述,使用Apple的可达性类或third-party检查您的互联网连接是否值得(最后一个是ARC和GCD兼容)

答案 1 :(得分: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
}