MFMailComposeViewController will not dismiss

Hi…

I am using Jason’s MFMailComposeViewController class to send mail… something like this:

dim mailControl as new Extensions.MFMailComposeViewController
mailControl.setSubject “my subject”
mailControl.setMessage “this is the body”
mailControl.setToRecipients Array(“xxx@company.com”)

if Extensions.MFMailComposeViewController.canSendMail then
mailControl.PresentInView(self)
end if

The view opens OK… when I tap Send the mail is sent OK but the MFMailComposeViewController does not dismiss and return to my previous view (self). If I tap Cancel I get the dialog asking is I want to save the draft, etc but after I tap that response the MFMailComposeViewController also does not dismiss. (my app is essentially frozen in this view.)

I have other places in my app where I use essentially the same code and it works fine… i.e. the MFMailComposeViewController does dismiss after the mail is sent.

Has anyone else seen this and found a solution?

Thanks,
Jim

As documented by Apple you get a call to the delegate when it’s done and there you can dismiss it.

I know because I just implemented it for my FileMaker iOS Plugin :slight_smile:

Hi Christian…

It looks like Jason is already doing that in his class… although I am not great with declares… and it makes it all the more difficult since the code only runs in a built app and not the debugger.

What I do not understand is why this same code works ok when I call if from other views in the app… I am just running the above code in the action event of a button.

Hi James,
This problem is likely caused by the variable you declared going out of scope. Add a property to your view and use that instead so the object is not destroyed at the end of the method (the delegate method can’t use the object in the callback if ceases to exist!)

Hopefully this helps,
Jason

Jason…

Thanks for the response…

If I understand you correctly… I added the Property I called “mailControl” Type “MFMailComposeViewController” to the View where my “send mail” button lives. In the Open event for that View I create a new instance of that Property… and when the button is tapped I:

mailControl.setSubject “My subject”
mailControl.setMessage “here is the body”
mailControl.setToRecipients Array(“info@company.com”)

if Extensions.MFMailComposeViewController.canSendMail then
mailControl.PresentInView(self)
end if

… the “mail view” opens and taping Send does send the mail but the “mail view” still does/will not dismiss.

Jim

Hmm, I’ve had people reach out to me with this problem before and that’s always been the solution. Would you be able to add a MsgBox in the callback that calls dismiss to confirm it is being called by your app?

I added a msgbox to the end of the “PresentInView” method displaying the mparentViewController.Title… and another msgbox also displaying the mparentViewController.Title at the top (before the declare) in the “dismiss” method…

The first msgbox correctly displays the title of the calling view… but the 2nd msgbox is blank… so “dismiss” is being called but it does seem that something may be stepping on that parent view…

Any idea are appreciated.

Jim

I wonder if there is an exception occurring. Try adding something in the Unhandled exception event handler and see if it is called? Grasping at straws here…

I already have implemented the unhandled exception event… It is not being called.

I will keep playing around… there must be something…

Thanks for trying
Jim

Jason…

I found my problem… totally my fault (as usual)! I had some old code in the view’s deactivate event that closed the view. Worked fine as long as that view was always at the end of the stack… but now with the “mail view” at the end there was no view to go back to.

Sorry to have taken your time.

I’m glad you were able to resolve this.