Iphone 在MFMailComposeViewController Delegate中处理邮件草稿(即MFMailComposer结果已保存)

Iphone 在MFMailComposeViewController Delegate中处理邮件草稿(即MFMailComposer结果已保存),iphone,cocoa-touch,Iphone,Cocoa Touch,我正在编写一个简单的应用程序(使用Xcode 4.2和iOS 5,使用iOS模拟器进行测试)。这会发送电子邮件,电子邮件合成窗口会像往常一样以非模态形式打开。电子邮件合成的可能结果之一是“另存为草稿”,即MFMailComposer结果已保存。在这种情况下,如何检索保存的草稿?或者更好的是,我可以取消这个选项吗?(即,即使用户在“邮件撰写”窗口中进行了任何修改,也不应显示“另存为草稿”选项。是否需要帮助 在ViewController.h(头文件) 在ViewController.m文件中: -

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

在ViewController.h(头文件)

在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];
}

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

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

-(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];
}