我有一个应用程序,允许用户从他们的 iPhone 发送测试电子邮件。我的应用程序调用一个方法来激活撰写邮件功能,如下所示:
-(void)displayComposerSheet
{
//set up a way to cancel the email here
//picker is an instance of MSMailComposeViewController already declared in the .h file
[picker setSubject:@"Test Mail"];
// Set up recipients
// Attach an image to the email
NSString *path = [[NSBundle mainBundle] pathForResource:@"Icon" ofType:@"png"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"Icon"];
// Fill out the email body text
NSString *emailBody = @"This is a test mail.";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
NSLog(@"mail is working");
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
emailLabel.hidden = NO;
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
emailLabel.text = @"Mail sending canceled.";
break;
case MFMailComposeResultSaved:
emailLabel.text = @"Mail saved.";
break;
case MFMailComposeResultSent:
{
emailLabel.text = @"Mail sent.";
NSLog(@"It's away!");
UIAlertView *emailAlertView = [[UIAlertView alloc] initWithTitle:@"Sent!" message:@"Mail sent successfully." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[emailAlertView show];
[self dismissModalViewControllerAnimated:YES];
[self.navigationController popViewControllerAnimated:YES];
}
break;
case MFMailComposeResultFailed:
{
emailLabel.text = @"Mail sending failed.";
}
break;
default:
{
emailLabel.text = @"Mail not sent.";
}
break;
}
}
我的问题是当撰写电子邮件功能处于活动状态时,我无法退出此功能并返回我的应用程序。摆脱这种情况的唯一方法是实际继续并发送消息。导航栏的左上角有一个默认的“取消”栏按钮,单击该按钮后,我提供了三个选项:“删除草稿”、“保存草稿”和“取消”。如果我选择“删除草稿”,它只会将我返回到撰写消息屏幕。我有没有办法让用户在启动撰写邮件功能后但在发送之前返回应用程序?有没有办法为“取消”栏按钮添加额外的功能来实现这一点?
提前感谢所有回复的人。