Bug 23115 - iOS8 MFMailComposeViewController
Summary: iOS8 MFMailComposeViewController
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: master
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-09-17 18:46 UTC by Ben Bishop
Modified: 2014-09-18 10:04 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Ben Bishop 2014-09-17 18:46:08 UTC
Okay, here's what I see when I build against the iOS SDK 8. I make in instance of MFMailComposeViewController. Pre-populate To, Subject, and MessageBody. Then I wire up the Finished event handler. When I present the view controller, the Finished event handler fires immediately and the the MFComposeResultEventArgs Result is set to MFMailComposeResult.Cancelled. This also happens even when I don't pre-populate To, Subject, and MessageBody. My guess it's a bug. Building against the iOS7.1 SDK works fine.

var to = _theaterEmail;
var subject = "Question";
var body = String.Empty;
var mailer = new MFMailComposeViewController ();

mailer.SetToRecipients(new string[] { to });
mailer.SetMessageBody(body, false);
mailer.Finished += MailerFinished;

await PresentViewControllerAsync(mailer, true);

// ....

void MailerFinished(object sender, MFComposeResultEventArgs e)
    //This fires immediately after await PresentViewControllerAsync(mailer, true)
   // e.Result is reporting MFMailComposeResult.Cancelled

And the Application Output Windows reports this:
2014-09-17 10:35:56.485 MyAppName[2084:37301] viewServiceDidTerminateWithError: 
Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "The operation couldn’t be completed. (_UIViewServiceInterfaceErrorDomain error 3.)" 
UserInfo=0x7d3a7fb0 {Message=Service Connection Interrupted}

This seems to only happen in the simulator.

Even in the simulator MFMailComposeViewController.CanSendMail is returning true
Comment 1 Rolf Bjarne Kvinge [MSFT] 2014-09-18 08:42:13 UTC
It looks like iOS changed their refcounting a bit, and the native MFMailComposeViewController ends up freed if the managed one is.

Can you try putting the MFMailComposeViewController in a class-level variable, and see if that helps?
Comment 2 Sebastien Pouliot 2014-09-18 09:13:57 UTC
(collision) note: using a class variable does not change the behaviour

> Finished event handler fires immediately

There's a slight delay (see below). The PresentViewControllerAsync returns, without being (user) cancelled, which is why the `Finished` event is called.

2014-09-18 09:03:14.350 b23115[98913:1145747] CanSendMail: True
2014-09-18 09:03:15.660 b23115[98913:1145747] await completed
Thread started:  #3
2014-09-18 09:03:33.221 b23115[98913:1146028] Cancelled

iOS tells us (to very clear) why that was cancelled just afterward in the logs.

2014-09-18 09:03:33.248 b23115[98913:1145747] viewServiceDidTerminateWithError: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "The operation couldn’t be completed. (_UIViewServiceInterfaceErrorDomain error 3.)" UserInfo=0x7b5c8690 {Message=Service Connection Interrupted}

This looks like an Apple iOS8/simulator change (as there's no Xamarin/iOS version specific code in there, not even new 8.0 API in MessageUI).

I'm not sure the simulator should be returning `true` for `CanSendMail` (since nothing is setup to do so) and it's possible the `MFMailComposeViewController` detect this and cancel itself.
Comment 3 Sebastien Pouliot 2014-09-18 09:36:46 UTC
Other people are having the same iOS error (logs) when using the Xcode6/iOS8 simulator with ObjC:
Comment 4 Sebastien Pouliot 2014-09-18 10:04:29 UTC
It's a known issue (first reported in beta5) that Apple will need to fix. Sadly there's no workaround listed anywhere :(