我想從我的應用程序發送郵件。我正在做Swift的第一步,而且我堅持了一點。我想按下按鈕並直接發送電子郵件。我想從我的TextField獲取Subject和MessageBody的數據。包括來自我的TextField的發件人數據(請查看截圖) 這是怎麼回事? 這是我的代碼:直接從應用程序發送電子郵件 - Swift
@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(["[email protected]"])
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搜索什麼?我添加了一個問題 –
類似主題...你不是第一個問這個問題的人。甚至沒有第十... –