【发布时间】:2019-04-11 04:52:58
【问题描述】:
我正在尝试在我的 xamarin 表单项目中发送电子邮件,我在 iPhone 模拟器和 iPhone 设备上都进行了尝试。当我按下 iPhone 上的发送电子邮件按钮时,没有任何反应,甚至没有出现调试错误。我还确保我在设备上使用我的电子邮件登录。
我使用了 serviceDependency 并按照此链接中的设置进行了操作: https://developer.xamarin.com/recipes/ios/shared_resources/email/send_an_email/
我的界面:
public interface InterfaceEmail
{
void sendEmail();
}
iOS 实现:
[assembly: Xamarin.Forms.Dependency(typeof(SendEmail))]
namespace myProject.iOS
{
public partial class SendEmail : InterfaceEmail
{
MFMailComposeViewController mailController;
public SendEmail() {}
public void sendEmail()
{
if (MFMailComposeViewController.CanSendMail)
{
mailController = new MFMailComposeViewController();
mailController.SetToRecipients (new string[] {"my@email.com"});
mailController.SetSubject ("test mail");
mailController.SetMessageBody ("This is a test", false);
mailController.Finished += (object sender, MFComposeResultEventArgs e) =>
{
Console.WriteLine(e.Result.ToString());
e.Controller.DismissViewController(true, null);
};
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailController, true, null);
}}}}
在我的共享代码中实现:
async void Handle_ToolbarButton(object sender, System.EventArgs e)
{
var action = await DisplayActionSheet("What do you want to do?", "Abort", null, "Send email");
if(action == "Send email")
{
DependencyService.Get<InterfaceEmail>().sendEmail();
}
}
有人知道这里可能出了什么问题吗?
【问题讨论】: