C# Xamarin iOS-如何发送电子邮件
我尝试了以下教程: 但是,当我运行代码时,它从未进入CanSendMail,它总是点击Else语句 代码C# Xamarin iOS-如何发送电子邮件,c#,ios,email,xamarin,C#,Ios,Email,Xamarin,我尝试了以下教程: 但是,当我运行代码时,它从未进入CanSendMail,它总是点击Else语句 代码 public partial class ContactController : BaseController { MFMailComposeViewController mailController; public ContactController() : base(null, null) { } public override
public partial class ContactController : BaseController
{
MFMailComposeViewController mailController;
public ContactController()
: base(null, null)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
View.BackgroundColor = UIColor.White;
var title = new UILabel(new RectangleF(-110, 80, 320, 30));
title.Font = UIFont.SystemFontOfSize(24.0f);
title.TextAlignment = UITextAlignment.Center;
title.TextColor = UIColor.Black;
title.Text = "Contact";
if (MFMailComposeViewController.CanSendMail)
{
mailController = new MFMailComposeViewController();
// do mail operations here
mailController.SetToRecipients(new string[] { "john@doe.com" });
mailController.SetSubject("mail test");
mailController.SetMessageBody("this is a test", false);
mailController.Finished += (object s, MFComposeResultEventArgs args) =>
{
Console.WriteLine(args.Result.ToString());
args.Controller.DismissViewController(true, null);
};
this.PresentViewController(mailController, true, null);
}
else { Console.WriteLine("Email can't be sent"); }
var body = new UILabel(new RectangleF(50, 120, 220, 100));
body.Font = UIFont.SystemFontOfSize(12.0f);
body.TextAlignment = UITextAlignment.Center;
body.Lines = 0;
body.Text = @"This is the content view controller.";
View.Add(title);
View.Add(body);
}
}
谁能帮我一下吗
谢谢我只需要在设备设置中启用电子邮件帐户。设备是否启用了任何电子邮件帐户?因为我不经常使用它。谢谢@SKall,现在一切正常。