MFMailComposeViewController trouble?

Hi,

My code previously worked with no problems, and as far as I know I haven't actually touched this code at all. In fact I have about 5 separate compose mail sections across my app and they are now all broken - crashing on the following error only when run on my device (emulator is fine).

Error:
Could not initialize an instance of the type 'MonoTouch.MessageUI.MFMailComposeViewController': the native 'init' method returned nil.
It is possible to ignore this condition by setting MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure to false.

Code snippet:
btnShareViaEmail.TouchUpInside += (sender, e) => {
MFMailComposeViewController mailView = new MFMailComposeViewController(); <-- System.exception mailView.SetSubject("string"); mailView.SetMessageBody("string", true); mailView.Finished += (object s, MFComposeResultEventArgs args) => {
args.Controller.DismissViewController(true, null);
};
this.PresentViewController(mailView, true, null);
};

I've cleaned my build a few times thinking this was just one of those weird ones. No luck. Did I miss a code-breaking change in a recent update or something?

Any help would be greatly appreciated.
Cheers.

Posts

  • TylerBurkeTylerBurke AUMember

    Apologies for the code being hard to read.. these forums do some weird things.

    btnShareViaEmail.TouchUpInside += (sender, e) => { MFMailComposeViewController mailView = new MFMailComposeViewController(); <-- System.exception mailView.SetSubject("string"); mailView.SetMessageBody("string", true); mailView.Finished += (object s, MFComposeResultEventArgs args) => { args.Controller.DismissViewController(true, null); }; this.PresentViewController(mailView, true, null); };

  • TylerBurkeTylerBurke AUMember
    edited January 2014

    So this error was being caused by the device not having any email accounts set up - for anyone who may run into this in the future.

    I guess you need to be careful and wrap mail operations in a a try catch sequence.

Sign In or Register to comment.