在MFMailComposeViewControllerDelegate中处理邮件草稿(即MFMailComposeResultSaved)

时间:2012-05-03 20:44:21

标签: iphone cocoa-touch

我正在编写一个简单的应用程序(使用Xcode 4.2和iOS 5,使用iOS模拟器进行测试)。这会发送电子邮件,并且电子邮件撰写窗口会像往常一样以非模态形式打开。电子邮件撰写的可能结果之一是“另存为草稿”,即MFMailComposeResultSaved。在这种情况下如何检索已保存的草稿?或者更好的是,我可以取消此选项吗? (即使用户在'邮件撰写'窗口中进行了任何修改,它也应该显示'另存为草稿'选项。请帮忙吗?

在ViewController.h(头文件)

-(void)showEmailComposer;
-(void) displayComposerSheet;

在ViewController.m文件中:

-(void)showEmailComposer {

    NSLog(@"showEmailComposer: begin");

Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil)
{
    if ([mailClass canSendMail]) {
        NSLog(@"showEmailComposer: Calling displayComposerSheet");
        [self displayComposerSheet];

    }
}
 }


#pragma mark -
#pragma mark Compose Mail

-(void) displayComposerSheet {
mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[self presentModalViewController:mailComposer animated:YES];
}


-(void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {

NSString *alertTitle;
NSString *alertMsg;

// Notifies users on errors, if any
switch (result) {

    case MFMailComposeResultCancelled:
        alertTitle = @"Cancelled";
        alertMsg = @"Mail composition got cancelled";
        break;
    case MFMailComposeResultSaved:
        alertTitle = @"Success - Saved";
        alertMsg = @"Mail got saved successfully!";
        break;
    case MFMailComposeResultSent:
        alertTitle = @"Success - Sent";
        alertMsg = @"Mail sent successfully!";
        break;
    case MFMailComposeResultFailed:
        alertTitle = @"Failure";
        alertMsg = @"Sending the mail failed";
        break;
    default:
        alertTitle = @"Failure";
        alertMsg = @"Mail could not be sent";
        break;
}

UIAlertView *alert = [[UIAlertView alloc] 
                      initWithTitle:alertTitle
                      message:alertMsg
                      delegate:nil
                      cancelButtonTitle:@"OK"
                      otherButtonTitles:nil];
[alert show];

[self dismissModalViewControllerAnimated:YES];
}

1 个答案:

答案 0 :(得分:1)

如果用户选择将邮件保存到草稿,则邮件位于“邮件”应用程序的“草稿”目录中。如果用户选择发送邮件,则邮件位于“邮件”应用程序的“发件箱”目录中。所以我的建议是,通知用户“邮件”应用程序负责邮件发送和编辑。