MFMailComposeViewController sometimes crashes when dismissed

plutonijplutonij CHMember

found myself at a very strange problem. In the application we are developing, there is a feature to send the mail from the app itself.

According to Xamarin recipes, the MFMailComposeViewController is the way to go for the Xamarin.ios.

As it seems there is a problem with just some of the devices, however the pattern is to me unclear.

While pressing the button "Send" or Cancel, the Finished delegate is called. This part should normally dismiss the MailViewController.

On some of the devices the behaviour is as expected, the Mail controller is removed from the screen and the underlying controller is displayed. On some devices however, the mail controller stays on top, and the app is not responding anymore. The debugger does not show anything.

Did anybody face this issue so far? Could this be somehow solved? I was reading some of the similar behavior in obj-c or swift code, however their solution did not help me.

This is my code:

private void OnSendMailClick(object sender, EventArgs e)
        if (MFMailComposeViewController.CanSendMail)
            string receiptText = trx.isReversed ?
                Utilities.GetTransactionAndRefundReceipt(trx, manager) : Utilities.GetReceipt(trx, true);

            var mailController = new MFMailComposeViewController();
            mailController.SetSubject(String.Format("Receipt number: {0}", trx.STAN));
            mailController.SetMessageBody(receiptText, true);
            mailController.Finished += OnSendResult;

            PresentViewController(mailController, true, null);

and the Finished delegate looks like this:

private void OnSendResult(object sender, MFComposeResultEventArgs e) => e.Controller.DismissViewController(true, null);

Sign In or Register to comment.