title: Why didFinishWith delegate method is called automatically while using MFMailComposeViewController in swift iOS?
body: <p>I am trying to present <code>MFMailComposeViewController</code> to send email but the problem is that <code>MFMailComposeViewController</code> pop is dismissed automatically as soon as it presents. The <code>didFinishWith</code> delegate method is called automatically just after present the <code>MFMailComposeViewController</code>, I don't know why it's happening.</p>
  <pre><code>import UIKit
  import Alamofire
  import MessageUI
  class MyProfileViewController: UIViewController, MFMailComposeViewControllerDelegate {
  
  override func viewDidLoad() {
      super.viewDidLoad()
          
          let senderMail = [&quot;xyz@gmail.com&quot;]
          let mailComposer = MFMailComposeViewController()
          guard MFMailComposeViewController.canSendMail() else{
              CommonUtils.showToast(message: &quot;Mail services are not available&quot;)
              return
          }
          mailComposer.setToRecipients(senderMail)
          mailComposer.mailComposeDelegate = self
          self.present(mailComposer, animated: true, completion: nil)
          
      }
      
  }
  
  func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
      
      switch (result){
      case MFMailComposeResult.cancelled:
          print(&quot;Mail cancelled&quot;);
          break;
      case MFMailComposeResult.saved:
          print(&quot;Mail saved&quot;);
          break;
      case MFMailComposeResult.sent:
          print(&quot;Mail sent&quot;);
          break;
      case MFMailComposeResult.failed:
          print(&quot;Mail sent failure: %@&quot;, error?.localizedDescription);
          break;
      default:
          break;
      }
      // Close the Mail Interface
      controller.dismiss(animated: true)
  }
  </code></pre>