I do the standard functionality of sending messages with MFMailComposeViewController
.
My code:
if MFMailComposeViewController.canSendMail()
{
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients(["[email protected]"])
mail.setSubject("Subject")
mail.setMessageBody("Some Text", isHTML: false)
self.presentViewController(mail, animated: true, completion: nil)
}
Controller do not open and I see a message in the console that have never seen.
[MC] Filtering mail sheet accounts for bundle ID: [My Bundle ID], source account management: 1
[MC] Result: NO
Help please.
If a mail account has been set at the device where you try to test your application there is no problem. Please create a mail account.
For Swift 3.0.1 - 4.2 Compatible
if MFMailComposeViewController.canSendMail()
{
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients(["[email protected]"])
mail.setSubject("Subject")
mail.setMessageBody("Some Text", isHTML: false)
self.present(mail, animated: true, completion: nil)
}
I had the same error though it works perfectly on my device with iOS 10.1.1. I had a similar problem and found that the Mail Composer would only work on iOS 9 in the simulator, there is some sort of bug with iOS 10 and running Mail Composer on the simulator with my current knowledge.
Update I have also tested this with a device with iOS 11.4 and got the same results.
Tried these calls to open mail on the simulator and they did not work. Though work they work fine on a real device.
UIApplication.shared.keyWindow?.rootViewController?.present(mail, animated: true)
self.navigationController?.present(mail, animated: true, completion: nil)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With