我的代码出错了。我知道有很多关于如何使按钮在swift中发送电子邮件的教程,但我不明白我的代码有什么问题。有人可以帮助解释我做错了什么吗?感谢。
import UIKit
import MessageUI
class AboutUsVC: UIViewController, MFMessageComposeViewControllerDelegate {
func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {
}
func configureMailController() -> MFMessageComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self as? MFMailComposeViewControllerDelegate
mailComposerVC.setToRecipients(["Test@gmail.com"])
mailComposerVC.setSubject("App - Help Contact")
return mailComposerVC()
}
func showMailError() {
let sendMailErrorAlert = UIAlertController(title: "Sorry, couldn't send", message: "Sorry, we are having some troubles sending the message right now. :(", preferredStyle: .alert)
let dismiss = UIAlertAction(title: "Ok", style: .default, handler: nil)
sendMailErrorAlert.addAction(dismiss)
self.present(sendMailErrorAlert, animated: true, completion: nil)
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true, completion: nil)
}
答案 0 :(得分:0)
在您的代码中,更改以下代码
func configureMailController() -> MFMessageComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self as? MFMailComposeViewControllerDelegate
mailComposerVC.setToRecipients(["Test@gmail.com"])
mailComposerVC.setSubject("App - Help Contact")
return mailComposerVC()
}
与
func configureMailController() -> MFMailComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients(["contact.Studio228@gmail.com"])
mailComposerVC.setSubject("In-Dose - Help Contact")
return mailComposerVC
}