Ich habe eine App erstellt, die eine vorab ausgefüllte E-Mail sendet. Die E-Mail wird perfekt gesendet, der Mail-Composer wird jedoch nicht geschlossen. Unten ist mein Code. Jede Hilfe wird geschätzt.MFMailComposeViewController wird nicht geschlossen
@IBAction func sendEmail(_ sender: Any)
{
let mailComposeViewController = configuredMailComposeViewController()
if MFMailComposeViewController.canSendMail() {
self.present(mailComposeViewController, animated: true, completion: nil)
} else {
self.showSendMailErrorAlert()
}
}
func configuredMailComposeViewController() -> MFMailComposeViewController {
let subject = "subject"
let body = "body"
let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self
// Configure the fields of the interface.
composeVC.setToRecipients(["[email protected]"])
composeVC.setSubject(subject)
composeVC.setMessageBody(body, isHTML: false)
return composeVC
}
func showSendMailErrorAlert() {
let sendMailErrorAlert = UIAlertView(title: "Could Not Send Email", message: "Your device could not send e-mail. Please check e-mail configuration and try again.", delegate: self, cancelButtonTitle: "OK")
sendMailErrorAlert.show()
}
// MARK: MFMailComposeViewControllerDelegate Method
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
switch result {
case .cancelled:
break
case .saved:
break
case .sent:
break
case .failed:
break
}
controller.dismiss(animated: true, completion: nil)
}
Ich habe mehrere Vorschläge ausprobiert, die ich hier gefunden habe und nichts scheint zu funktionieren.
Nicht verknüpft, aber Sie sollten 'configuredMailComposeViewController' in der' if' Anweisung aufrufen. Warum erstellen Sie es, wenn Sie keine E-Mails senden können? – rmaddy
Fügen Sie einen Haltepunkt hinzu, um sicherzustellen, dass controller.dismiss (animiert: true, completion: nil) aufgerufen wird. –