iOS:MFMailComposeViewController没有关闭

时间:2017-11-16 12:26:31

标签: ios objective-c uiviewcontroller mfmailcomposeviewcontroller mfmailcomposer

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

用于打开MFMailComposeViewController模态窗口的方法:

-(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(发送) - 发送电子邮件,但模态窗口保持打开状态;多次单击该按钮会导致发送多个电子邮件,而模式窗口不会被关闭。 Abbrechen(取消) - 没有任何事情发生

如何解雇确保MFMailComposeViewController在点击这些按钮后被解雇?

Screenshot

1 个答案:

答案 0 :(得分:2)

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

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