您好我想从我的应用程序打开电子邮件程序,并且已经定义了正文.我可以打开电子邮件但不知道如何将eMail的主体定义为给定的参数以显示给定的标准文本.有人可以帮忙吗?继承人我用来打开电子邮件的代码:
//EMAIL let email = "foo@bar.com" let urlEMail = NSURL(string: "mailto:\(email)") if UIApplication.sharedApplication().canOpenURL(urlEMail!) { UIApplication.sharedApplication().openURL(urlEMail!) } else { print("Ups") }
解决方法
您可以使用MFMailComposeViewController执行此操作:
import MessageUI let mailComposerVC = MFMailComposeViewController() mailComposerVC.mailComposeDelegate = self mailComposerVC.setToRecipients(["email@email.com"]) mailComposerVC.setSubject("Subject") mailComposerVC.setMessageBody("Body",isHTML: false) self.presentViewController(mailComposerVC,animated: true,completion: nil)
此外,您需要实现mailComposeController:didFinishWithResult:error:来自MFMailComposeViewControllerDelegate,您应该关闭MFMailComposeViewController