[英]iOS: How do I detect if an email has been successfully sent?
我正在尝试检查是否已发送电子邮件并显示警报以使用户知道。
我在下面尝试了委托方法,但不幸的是,如果用户也取消,它将显示警报消息。 任何帮助将不胜感激和奖励。
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error{
if (error) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:
[NSString stringWithFormat:@"Error %@", [error description]] delegate:self
cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
}
NSLog(@"email sent");
}
}
当该函数被调用时,这意味着电子邮件中发生了某些事情,因为MFMailComposeViewController
已完成。 要知道实际发生了什么,您必须查看result
的值,该值可以是以下任意一种:
MFMailComposeResultCancelled
MFMailComposeResultSaved
MFMailComposeResultSent
MFMailComposeResultFailed
就像rmaddy在评论中说的那样,您无法100%确定电子邮件是实际发送的(可能会卡在发件箱中)。 MFMailComposeResultSent
表示的是,该电子邮件已发送到邮件应用程序,该应用程序将尽快将其发送。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.