Closed WillAutioItrax closed 7 years ago
I have the exact same issue, works in android, but not IOS
var messenger = CrossMessaging.Current.EmailMessenger;
if (messenger.CanSendEmailAttachments)
{
var email = new EmailMessageBuilder()
.To("")
.Subject("")
.BodyAsHtml("")
.WithAttachment(filePath, "image/jpeg")
.Build();
messenger.SendEmail(email);
}
I get this error:
Warning: Attempt to present <MFMailComposeViewController: 0x104c50800> on <Xamarin_Forms_Platform_iOS_PageRenderer: 0x103d45c50> whose view is not in the window hierarchy!
Ok, i found the solution. in Xamarin.Plugins/Messaging/Plugin.Messaging.iOSUnified/MessagingExtensions.cs there is a method called GetVisibleViewController ,all i did was replace the code that was there with this:
private static UIViewController GetVisibleViewController(UIViewController controller)
{
controller = controller ?? UIApplication.SharedApplication.KeyWindow.RootViewController;
if (controller.PresentedViewController == null)
return controller;
if (controller.PresentedViewController is UINavigationController)
{
return ((UINavigationController)controller.PresentedViewController).VisibleViewController;
}
if (controller.PresentedViewController is UITabBarController)
{
return ((UITabBarController)controller.PresentedViewController).SelectedViewController;
}
return GetVisibleViewController(controller.PresentedViewController);
}
And now it works fine :) ref: https://stackoverflow.com/questions/41241508/xamarin-forms-warning-attempt-to-present-on-whose-view-is-not-in-the-window
@madareklaw Thanks for the investigation and fix. I'll have a look at including this in the upcoming v5 release that I hope to publish sometime this week-end
@cjlotz No probs
Awesome! Thanks you guys!
I ended up using some code similar to what @jamesmontemagno was using in his Media plugin to resolve the view controller. From my testing it seems to work fine. Let me know if you run into further issues with this.
@madareklaw @cjlotz : How do I make changes suggested by @madareklaw in MessagingExtension.cs file and build a plugin file for my Xamarin.Forms project? Can you please help me. Thank you.
@kartiksolanki Upgrade to v5 of the plugin. The fixes are included in there
@cjlotz : Thank you :)
Did the upgrade - works like a charm. This is awesome! Thanks!
Hi. I am developing in Xamarin Forms, VS2017, a PCL project. The following code works fine on Droid:
` var emailMessenger = CrossMessaging.Current.EmailMessenger;
It opens an email client and pre-populates the desired items.
However on iOS, by executing the same PCL code I do not get an email client opening. I do get a warning in Output which I suspect indicates an issue.
Warning: Attempt to present <MFMailComposeViewController: 0x1710b200> on <Xamarin_Forms_Platform_iOS_PageRenderer: 0x17a2e820> whose view is not in the window hierarchy!
Any direction on how to fix this is appreciated.