ios - 需要帮助关闭 iOS 中的电子邮件编辑器屏幕

标签 ios uiviewcontroller mfmailcomposeviewcontroller

我有一个应用程序,允许用户从他们的 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;
    }

}

我的问题是,当撰写电子邮件功能处于事件状态时,我无法退出此功能并返回到我的应用程序。解决这个问题的唯一方法是实际继续发送消息。导航栏的左上角出现一个默认的“取消”栏按钮,单击该按钮后,会出现三个选项:“删除草稿”、“保存草稿”和“取消”。如果我选择“删除草稿”,除了返回撰写消息屏幕之外,它不会执行任何操作。有没有办法让用户在启动撰写邮件功能后但在发送之前返回应用程序?有没有办法向“取消”栏按钮添加额外的功能来实现此目的?

提前感谢所有回复的人。

最佳答案

您必须实现MFMessageComposeViewControllerDelegate- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result方法。

您将在此方法中关闭消息 View 。

编辑:我对 MFMailComposeViewControllerDelegate 感到困惑但目的与 MFMessageComposeViewControllerDelegate 相同

关于ios - 需要帮助关闭 iOS 中的电子邮件编辑器屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14263690/

相关文章:

ios - UIViewController 没有带有 UIModalPresentationFormSheet 的parentViewController?

ios - 无法使用解雇(动画: true,完成:nil)解雇邮件编辑器并且解雇ViewControllerAnimated不会作为选项出现

iPhone 不使用 MessageUI 发送电子邮件

ios - 使用 Pinterest SDK 发送到释放实例的消息

ios - 从非 ECSlidingViewController 打开 ECSlidingViewController

ios - 填充所有文本字段时如何启用按钮

objective-c - MFMailComposeViewController 导致其他控件改变位置

ios - 更正线程以从/向核心数据执行删除、插入和获取

在模拟器中激活时,iOS 通话状态栏不显示。这是正常行为吗?

ios - 如何在 xcode 4.5 的 UIscrollview 中显示图像边框?