Код: Выделить всё
import MessageUI
class Mail: UIViewController, MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
func send(title: String, address: [String], message: String, errorTitle: String, errorMessage: String) {
if MFMailComposeViewController.canSendMail() {
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setSubject(title)
mail.setToRecipients(address)
mail.setMessageBody(message, isHTML: false)
present(mail, animated: true, completion: nil)
} else {
let alert = UIAlertController(title: errorTitle, message: errorMessage, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true, completion: nil)
}
}
Код: Выделить всё
func contactWithDeveloper() {
Mail().send(title: "title", address: ["1@gmail.com"], message: "message", errorTitle: "errorTitle", errorMessage: "errorMessage")
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... il-message