当用户使用 MFMailComposeViewController 从 iPhone 成功发送邮件时,我需要显示警报消息。
我尝试使用 didFinishWithResult 委托(delegate),但它同时调用发送和取消,那么我们如何确定我们成功发送了消息?
最佳答案
Try this code
-(IBAction)Btn_EmailPressed:(id)sender{
if (![MFMailComposeViewController canSendMail]) {
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Email cannot be configure." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
return;
}else {
picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate=self;
[picker setToRecipients:nil];
[picker setSubject:@"Email"];
[picker setMessageBody:nil isHTML:NO];
NSArray *toRecipients = [[NSArray alloc] initWithObjects:lblSite.text,nil];
[picker setToRecipients:toRecipients];
[self presentModalViewController:picker animated:YES];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)mailController didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
NSString *msg1;
switch (result)
{
case MFMailComposeResultCancelled:
msg1 =@"Sending Mail is cancelled";
break;
case MFMailComposeResultSaved:
msg1=@"Sending Mail is Saved";
break;
case MFMailComposeResultSent:
msg1 =@"Your Mail has been sent successfully";
break;
case MFMailComposeResultFailed:
msg1 =@"Message sending failed";
break;
default:
msg1 =@"Your Mail is not Sent";
break;
}
UIAlertView *mailResuletAlert = [[UIAlertView alloc]initWithFrame:CGRectMake(10, 170, 300, 120)];
mailResuletAlert.message=msg1;
mailResuletAlert.title=@"Message";
[mailResuletAlert addButtonWithTitle:@"OK"];
[mailResuletAlert show];
[mailResuletAlert release];
[self dismissModalViewControllerAnimated:YES];
}
关于iphone - iPhone 中从 MFMailComposeViewController 发送邮件时显示成功提醒消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8385028/