I'm trying to add email capability to my IOS project made with Xamarin Forms. I'm using DependencyService to implement the email function and my IOS code is as follows:
public void SendEmail(string[] recipients, string subject, string body, string filePath, string fileName)
{
MFMailComposeViewController mailController;
if (MFMailComposeViewController.CanSendMail)
{
mailController = new MFMailComposeViewController();
mailController.SetToRecipients(recipients);
mailController.SetSubject(subject);
mailController.SetMessageBody(body, false);
mailController.AddAttachmentData(NSData.FromFile(filePath), "application/pdf", fileName);
mailController.Finished += (object s, MFComposeResultEventArgs args) =>
{
Console.WriteLine(args.Result.ToString());
args.Controller.DismissViewController(true, null);
};
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailController, true, null);
}
}
but when I test the implementation, nothing happens no errors or anything. I can continue to use the app as normal after the failed attempt to email. I understand this question has been asked here and here but I have already enabled an email account on my testing iPad's default mail app and have removed all instances of DisplayActionSheet in my PCL implementation.