MFMailComposeViewController dismisses automatically on simulator

Hello,
I'm displaying a `MFMailComposeViewController` using the below code.


if MFMailComposeViewController.canSendMail() {
  let mailComposeViewController = MFMailComposeViewController()
  mailComposeViewController.navigationBar.tintColor = .white
  mailComposeViewController.mailComposeDelegate = self
  mailComposeViewController.setToRecipients(["support@gmail.com"])
  mailComposeViewController.setSubject("Feedback")
  present(mailComposeViewController, animated: true)
} else {
  print("This device is not configured to send email. Please set up an email account.")
}


This worked just fine on both devices and simulators in Xcode 10.


In the new Xcode 11 simulators, the compose view controller dismisses by itself as soon as it appears. See here.



The following error also shows up in the Xcode console.

[Common] [FBSSystemService][0x5f27] Error handling open request for com.apple.MailCompositionService: { userInfo = { FBSOpenApplicationRequestID = 0x5f27; } underlyingError = ; } 2019-11-01 14:40:05.214158+0530 MailCompose[11289:262267] [Assert] Connection request invalidated without resuming our _serviceSessionConnection. This is an error. 2019-11-01 14:40:05.216901+0530 MailCompose[11289:262054] [General] #CompositionServices _serviceViewControllerReady: NSError Domain=_UIViewServiceInterfaceErrorDomain Code=0


This happens in all Xcode 11 versions. Is this an Xcode bug? Is there a workaround?
Thanks!

Replies

I have same issue.
- I have added gmail account on device's settings.
- Inside my app, by click on support email, I have open Mail composer

- But unfortunately, when I click on email, Composer opens but it is dissmissed within fraction of second without any action on simulator.
- I am using Xcode 11.3, Swift 5.

The simulator can't send mail.

Your code should be testing to see if the device can send mail...

https://stackoverflow.com/questions/32938348/how-to-use-mfmailcomposeviewcontroller-with-simulator