iOS: MFMailComposeViewController 没有关闭

iOS: MFMailComposeViewController not getting closed

我在我的应用程序中使用 MFMailComposeViewController 来撰写反馈电子邮件。 MFMailComposeViewController 显示,但无法关闭。

用于打开MFMailComposeViewController模态的方法window:

-(IBAction) feedbackBtnClicked:(id)sender {

    // Dismiss the Old View Controller
    [self dismissViewControllerAnimated:NO completion:NULL];

    // Present the New View Controller
    if ([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
        mail.mailComposeDelegate = self;
        [mail setSubject:@"Sample Subject"];
        [mail setMessageBody:@"Here is some main text in the email!" isHTML:NO];
        [mail setToRecipients:@[@"example@mail.com"]];

        [self presentViewController:mail animated:YES completion:NULL];
    }
    else
    {
        NSLog(@"This device cannot send email");
    }
}

点击按钮时会发生以下情况:

Senden(发送) - 电子邮件已发送,但模式 window 保持打开状态;多次单击该按钮会导致发送多封电子邮件,而模态 window 永远不会关闭。 Abbrechen(取消) - 没有任何反应

如何关闭以确保 MFMailComposeViewController 在单击这些按钮后被关闭?

您需要实现 MFMailComposeViewControllerDelegate 方法 mailComposeController:didFinishWithResult:error:,并关闭邮件视图控制器…

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
                 didFinishWithResult:(MessageComposeResult)result
{
  [self dismissViewControllerAnimated:YES completion:NULL];
}