Это сводит меня с ума. Этот фрагмент кода позволяет пользователю отправить электронное письмо с изображением, созданным в приложении. Все работает отлично, кроме self.dismiss(animated: true, completion: nil)
- MFMailComposeViewController
не сбрасывается.
Я использовал эти три возможные проблемы https://stackoverflow.com/a/13217443/5274566 в качестве начала решения проблемы. , но все равно не получится. Контроллер остается, несмотря на то, что письмо было отправлено или cancel
было нажато.
Добавлена реализация протокола MFMailComposeViewControllerDelegate
.
func mailOpen(alertAction: UIAlertAction) {
if MFMailComposeViewController.canSendMail() {
let mailcontroller = MFMailComposeViewController()
mailcontroller.mailComposeDelegate = self;
mailcontroller.setSubject("Subject")
let completeImage = newImage! as UIImage
mailcontroller.addAttachmentData(UIImageJPEGRepresentation(completeImage, CGFloat(1.0))!, mimeType: "image/jpeg", fileName: "Image")
mailcontroller.setMessageBody("<html><body><p>Message</p></body></html>", isHTML: true)
self.present(mailcontroller, animated: true, completion: nil)
} else {
let sendMailErrorAlert = UIAlertView(title: "Could Not Send Email", message: "Your device could not send the e-mail. Please check e-mail configuration and try again.", delegate: self, cancelButtonTitle: "Got it!")
sendMailErrorAlert.show()
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
self.dismiss(animated: true, completion: nil)
}
}//end of mail