I tried using the MFMailComposeViewController
to send an email in my app.
let email = "..."
let mailComposer = MFMailComposeViewController()
mailComposer.mailComposeDelegate = self
mailComposer.setToRecipients([email])
self.navigationController?.present(mailComposer, animated: true)
After running my app the composer screen is showing, but the cancel
and send
buttons are not showing. I tried many possible solution, as change tintColor
in both navigationControllers. For example:
mailComposer.navigationBar.tintColor = .red
But the "issue" persists.
Any ideas?
Please try these code
class TechSupportVC: UIViewController, MFMailComposeViewControllerDelegate {
let composeVC = MFMailComposeViewController()
override func viewDidLoad() {
super.viewDidLoad()
composeVC.mailComposeDelegate = self
composeVC.setToRecipients(["desiredEmail@gmail.com"])
composeVC.setSubject("My message")
}
func mailComposeController(_ controller: MFMailComposeViewController,
didFinishWith result: MFMailComposeResult,
error: Swift.Error?) {
controller.dismiss(animated: true, completion: nil)
}
@IBAction func sendPressed(_ sender: Any) {
guard MFMailComposeViewController.canSendMail() else {
showMailServiceErrorAlert()
return
}
composeVC.setMessageBody("Test credentials: \(firstAndLastNameTextField.text!)\nPhone: \(numberTextField.text!)\n\n\(messageTextView.text!)", isHTML: false)
self.present(composeVC, animated: true, completion: nil)
}