【发布时间】:2017-09-20 16:16:34
【问题描述】:
尝试通过以下方法发送电子邮件,但我不断收到 并且没有显示电子邮件ios表单。
" 尝试呈现 MFMailComposeViewController: 0x1560e1a00 on 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);
}
}
【问题讨论】:
-
您在什么情况下定义
SendEmail? (自定义表单的渲染器还是依赖服务?) -
我只有一个在 iOS 项目中实现的接口,方法是发送电子邮件。我愿意接受其他建议
-
@ColeXia 给出答案,我会接受的。非常感谢
标签: xamarin xamarin.ios