我正在编写一个简单的应用程序(使用 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];
}