【发布时间】:2016-12-21 19:41:17
【问题描述】:
这让我发疯了。这个 sn-p 代码允许用户发送一封电子邮件,其中包含在应用程序中创建的图像。除了 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
【问题讨论】:
标签: ios swift mfmailcomposeviewcontroller mfmailcomposer