【发布时间】:2017-08-01 15:43:43
【问题描述】:
我想从我的应用程序中发送邮件。我正在使用 Swift 迈出第一步,但我一直坚持下去。我想按一个按钮并直接发送电子邮件。我想从我的 TextField 中获取 Subject 和 MessageBody 的数据。包括来自我的 TextField 的发件人数据(请查看屏幕截图) 怎么做? 这是我的代码:
@IBAction func sendEmailButtonTapped(sender: AnyObject) {
let mailComposeViewController = configuredMailComposeViewController()
if MFMailComposeViewController.canSendMail() {
self.present(mailComposeViewController, animated: true, completion: nil)
} else {
self.showSendMailErrorAlert()
}
}
func configuredMailComposeViewController() -> MFMailComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self // Extremely important to set the --mailComposeDelegate-- property, NOT the --delegate-- property
mailComposerVC.setToRecipients(["primer@gmail.com"])
mailComposerVC.setSubject("Sending you an in-app e-mail...")
mailComposerVC.setMessageBody("Sending e-mail in-app is not so bad!", isHTML: false)
return mailComposerVC
}
func showSendMailErrorAlert() {
let sendMailErrorAlert = UIAlertView(title: "Could Not Send Email", message: "Your device could not send e-mail. Please check e-mail configuration and try again.", delegate: self, cancelButtonTitle: "OK")
sendMailErrorAlert.show()
}
// MARK: MFMailComposeViewControllerDelegate Method
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true, completion: nil)
}
【问题讨论】:
-
您的第一步不包括运行搜索吗?截图在哪里?你的问题是什么?
-
@ElTomato 搜索什么?我添加了一个问题
-
类似主题...您不是第一个提出这个问题的人。甚至不是第十...
-
@ElTomato 和?谢谢你的信息))
标签: swift email button action textfield