Hello guys ! I am trying to send an email from my app. I am trying to do it with the DependencyService. For now I am implementing it for iOS only and I have the following warning : " ConsultantsApp.iOS[486:47185] Warning: Attempt to present on whose view is not in the window hierarchy! " . This is the code from my class:
public class IMailSender : UIViewController, MailSender
{
MFMailComposeViewController mailController;
public IMailSender()
{
}
public void sendMail (string subject)
{
if (MFMailComposeViewController.CanSendMail) {
mailController = new MFMailComposeViewController ();
mailController.SetToRecipients (new string[]{"stefan@edenofapps.com"});
mailController.SetSubject (subject);
mailController.SetMessageBody ("this is a test", false);
mailController.Finished += ( object s, MFComposeResultEventArgs args) => {
Console.WriteLine (args.Result.ToString ());
BeginInvokeOnMainThread (() => {
args.Controller.DismissViewController (true, null);
});
};
};
if (MFMailComposeViewController.CanSendMail) {
this.PresentViewController (mailController, true, null);
} else {
new UIAlertView("Mail not supported", "Can't send mail from this device", null, "OK");
}
}
}
And this is my AppDelegate class:
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
Forms.Init();
window = new UIWindow(UIScreen.MainScreen.Bounds);
window.RootViewController = App.GetMainPage().CreateViewController();
window.MakeKeyAndVisible();
return true;
}
}
Thanks in advance !