Post marked as unsolved
Click to stop watching this post.
You have stopped watching this post. Click to start watching again.
Post marked as unsolved with 0 replies
65
Views
MFMailComposeViewController duplicate email
Using MFMailComposeViewController for sending emails in a Mac Catalyst app sends the email twice.
I created an empty sample app to check, got the same results. The same code works fine on iOS (email only gets sent once). I use a Google account for my mailing on both platforms.
Am I doing something wrong? Any suggestions?
My code:
Swift
import UIKit
import MessageUI
class ViewController: UIViewController, MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if !MFMailComposeViewController.canSendMail() {
print("Cannot send mail")
return
}
let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self
composeVC.setSubject("Test subject")
composeVC.setMessageBody("Test body", isHTML: false)
self.present(composeVC, animated: true, completion: nil)
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true, completion: nil)
}
}