MFMailComposeViewController视图不会第二次解除

我有我认为是一个独特的问题。 我无法将我的电子邮件窗口解雇。 我正在使用Xcode 8。

第一次打开电子邮件时,电子邮件正确解散,但如果我再次打开电子邮件则不会。 如果我按“取消”,它不会给我“删除草稿”的选项。 如果我按“发送”,则会发送电子邮件,但窗口不会被忽略。

我的代码如下。 mailComposeController第一次被正确调用,但它永远不会被第二次调用。 有没有人对我失踪的东西有任何想法?

 let mail = MFMailComposeViewController() func sendEmail(body: String, subject: String) { if MFMailComposeViewController.canSendMail() { mail.mailComposeDelegate = self mail.setSubject(subject) mail.setMessageBody("\(body)", isHTML: false) if let data = (body as NSString).data(using: String.Encoding.utf8.rawValue){ //Attach File mail.addAttachmentData(data, mimeType: "text/plain", fileName: "data.txt") } present(mail, animated: true) } else { // show failure alert } } func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) { controller.dismiss(animated: true, completion: nil) } 

您需要每次都创建一个新的MFMailComposeViewController 。 在sendEmail移动你的mail声明工作……

 func sendEmail(body: String, subject: String) { if MFMailComposeViewController.canSendMail() { // Create a new MFMailComposeViewController… let mail = MFMailComposeViewController() mail.mailComposeDelegate = self mail.setSubject(subject) mail.setMessageBody("\(body)", isHTML: false) if let data = (body as NSString).data(using: String.Encoding.utf8.rawValue){ //Attach File mail.addAttachmentData(data, mimeType: "text/plain", fileName: "data.txt") } present(mail, animated: true) } else { // show failure alert } } 

至于为什么……?