ios - 写入错误的目标地址格式时,MFMailViewComposer 不会返回错误

标签 ios objective-c mfmailcomposeviewcontroller

当我尝试向不存在的地址(例如“hello”)发送电子邮件时,MFMail Composer 应该返回 MFMailComposeResultFailed,我猜,但这不会发生,并且消息似乎已正确发送(显然,则不发送)。我对“邮件”进行了相同的尝试,在这种情况下,“邮件”回答发送消息时出错,但是,当我在应用程序中执行相同操作时,没有错误。我该如何解决这个问题?

这是我进入邮件屏幕时使用的代码:

if ([MFMailComposeViewController canSendMail]) {
    MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc]init];
    mailer.mailComposeDelegate = self;
    [mailer setSubject:@"Notification"];
    User *user = [user_array objectAtIndex:0];
      NSArray *toRecipients = [NSArray arrayWithObjects:user.eMail, nil];
      [mailer setToRecipients:toRecipients];

    [mailer setMessageBody:self.label1.text isHTML:NO];
    [self presentViewController:mailer animated:YES completion:nil];
    [mailer release];
}
else
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
                                                    message:@"Your device doesn't support the composer sheet"
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles: nil];
    [alert show];
    [alert release];
}

}

这是响应者的代码:

-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
NSString *string = @"";
switch (result)
{
    case MFMailComposeResultCancelled:
        string = @"cancelled";
        NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued.");
        break;
    case MFMailComposeResultSaved:
        NSLog(@"Mail saved: you saved the email message in the drafts folder.");
        break;
    case MFMailComposeResultSent:
        string = @"sent";
        NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send.");
        break;
    case MFMailComposeResultFailed:
        NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");
        break;
    default:
        NSLog(@"Mail not sent.");
        break;
}
// Remove the mail view
int abc = MFMailComposeErrorCodeSendFailed;
NSLog(@"ERROR LOG %i", abc);
[self dismissViewControllerAnimated:YES completion:nil];
if ([string isEqualToString:@"cancelled"]) {
    ViewController *second = [self.storyboard instantiateViewControllerWithIdentifier:@"Notif_detail"];
    [second setString1:self.string1];
    [second setString2:self.string2];
    [second setString3:self.string3];
    [second setString4:self.string4];
    [self.navigationController pushViewController:second animated:YES];
}
else if ([string isEqualToString:@"sent"]){

    ViewController *second = [self.storyboard instantiateViewControllerWithIdentifier:@"View"];
   [self.navigationController pushViewController:second animated:YES];
}

}

提前致谢!

最佳答案

我猜当 didFinishWithResult 被触发时实际上没有错误,因为消息已排队并且即将发送。由于消息未送达,当您从邮件服务器(smtp 代码)收到响应时,稍后会发生该错误。

关于ios - 写入错误的目标地址格式时,MFMailViewComposer 不会返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15342700/

相关文章:

ios - print - 后台或主线程操作

ios - Swift 3 计数计时器未能在 UILabel 中显示更新的数字

ios - 关于iOS CLLocation API CLLocationCoordinate2DIsValid,操作系统如何处理GPS是否有效?

ios - 从 UIPickerView 更改按钮图像

ios - iPad 上的 MFMailComposeViewController 黑屏

ios - MFMailComposeViewController iOS9 错误(在 iPad mini 4 上)

ios - 将 Storyboard 中的对象居中

ios - 从 UIImage 清除 UIView 绘图

ios - objective-C : Issue faced while editing multiple row simultaneously in table view

swift - MFMailComposeViewController 发送和取消都不起作用