我是IOS编程的新手,所以我不确定这是编程的主要部分还是什么复杂的东西,但我想在我的应用程序中添加一个反馈功能。也就是说,我正在考虑有一个名为"FeedBack“的按钮,当用户点击它时,它会将他们重定向到他们的本地电子邮件应用程序,并且' to‘部分已经填满了我的凭据。对如何做到这一点有什么建议吗?
发布于 2017-08-09 13:33:30
仅供参考,您不能从模拟器发送邮件,因此它会给出错误,请在此处处理,请尝试以下代码
import Foundation
import MessageUI
import UIKit
class test: UIViewController, MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
if MFMailComposeViewController.canSendMail()
{
sendEmail()
}
else
{
print("Mail services are not available")
return
}
}
func sendEmail() {
let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self
composeVC.setToRecipients(["youraddress@example.com"])
composeVC.setSubject("Any subject!")
composeVC.setMessageBody("this is your message body!", isHTML: false)
// Present the view controller modally.
self.present(composeVC, animated: true, completion: nil)
}
func mailComposeController(controller: MFMailComposeViewController,
didFinishWithResult result: MFMailComposeResult, error: NSError?) {
controller.dismiss(animated: true, completion: nil)
}
}https://stackoverflow.com/questions/45582289
复制相似问题