尝试发送一封电子邮件,调用以下方法,但我一直在努力 并且不会显示电子邮件ios表单。
"尝试提供MFMailComposeViewController:0x1560e1a00 Xamarin_Forms_Platform_iOS_PlatformRenderer:0x157b5c180 其视图不在窗口层次结构中!"
我需要做些什么才能让它发挥作用?
public void SendEmail()
{
string to="jo@gmail.com";
string subject="Test";
string body="This is a test email";
if (MFMailComposeViewController.CanSendMail)
{
var mailComposeViewController = new MFMailComposeViewController();
mailComposeViewController.SetToRecipients(new[] { to });
mailComposeViewController.SetSubject(subject);
mailComposeViewController.SetMessageBody(body, false);
mailComposeViewController.Finished += (s, args) =>
{
Xamarin.Forms.Device.BeginInvokeOnMainThread
(
() => { args.Controller.DismissViewController(true, null); }
);
};
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailComposeViewController, true, null);
}
}
答案 0 :(得分:0)
我们应该在窗口顶部找到正确的rootviewController。
试试这个:
import Data.Char
checkLast :: String -> Bool
checkLast [] = False
checkLast cs = isUpper $ foldr1 seq cs
并将您的最后一行代码修改为
var rootController = ((AppDelegate)(UIApplication.SharedApplication.Delegate)).Window.RootViewController.ChildViewControllers[0].ChildViewControllers[1].ChildViewControllers[0];