[英]Xamarin iOS - How to send emails
我已尝试按照以下教程进行操作: http : //developer.xamarin.com/recipes/ios/shared_resources/email/send_an_email/
但是,当我运行代码时,它永远不会输入CanSendMail总是会触及Else语句。
码
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);
}
}
有人可以帮我吗
谢谢
我只需要在设备设置中启用电子邮件帐户即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.