iphone - iPhone 中从 MFMailComposeViewController 发送邮件时显示成功提醒消息

标签 iphone email mfmailcomposeviewcontroller

当用户使用 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/

相关文章:

objective-c - 尝试在带有按钮的自定义单元格内创建 IBAction

ios - 从 MFMailComposeViewController 返回时 MonoTouch 应用程序崩溃

ios - 如何从 XMPP 库 ios 中获取所有注册用户?我试过这个但得到错误代码 404,找不到项目

java - 将电子邮件发送到以下服务器失败(apache commons - Java)

ios - 如何使 TableView 在重新加载后用新数据加载旧数据并在 ios 应用程序中 25 秒后隐藏旧数据

email - Apple Mail 7.0 中嵌入高 DPI 图像的奇怪行为

java - 如何修复 Android : could not find class java. awt.datatransfer.DataFlavor 上的 Spongy CaSTLe 错误

MFMailComposeViewController 在横向

处理图像的 Iphone 停止所有进程

Titanium 开发者上的 iPhone SDK "loading"