Question

Exception Message:

Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: 
Application tried to present a nil modal view controller on target <Navigator: 0x1bed0d0>.

Here is my code:

    partial void BtnTest (MonoTouch.Foundation.NSObject sender)
    {
        MFMailComposeViewController view = new MFMailComposeViewController();
        view.SetToRecipients(new string[]{"blubb@blubb.de"});
        view.SetMessageBody("Hier steht nun der zusammengestellt text :)", false);
        //view.MailComposeDelegate = new CustomMailComposeDelegate();
        view.SetSubject("Test");

        view.Finished += (s,e)=>
                     {
                            this.NavigationController.DismissModalViewControllerAnimated(true);
        };

        this.BeginInvokeOnMainThread(()=>
        {
            this.NavigationController.PresentModalViewController(view, true);
        });

    }

It works on iPad Emulator but not on the Device.

Was it helpful?

Solution

Is your device configured to send emails ? note that even if it is you should not consider it will be the case on every user devices.

IWO you should call MFMailComposeViewController.CanSendMail like this is documented by Apple. Two important quotes:

you must always check to see if the current device is configured to send email at all using the canSendMail method

and

You should not attempt to use this interface if the canSendMail method returns NO.

Example:

   if (MFMailComposeViewController.CanSendMail) {
       ... your code ...
   } else {
       ... show warning, like an UIAlertView
   }

OTHER TIPS

Move this declaration outside of your method. It is most likely getting GC as soon as it goes out of scope.

MFMailComposeViewController view;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top