我有一些代码错误。我对此很陌生,我正在努力自学。我在网上找到了大部分答案,但似乎找不到关于这个特定问题的任何信息。我想在应用程序中发送一封电子邮件,但只要我按下电子邮件按钮,MFMailViewController 就不会出现。就像我的 UIButton 不工作一样。但我知道我将它作为 IBAction。到目前为止,这是我的代码。任何帮助深表感谢。
import UIKit
import MessageUI
class RequestService: UIViewController,MFMailComposeViewControllerDelegate {
@IBOutlet weak var CustomerName: UITextField!
@IBOutlet weak var emailButton: UIButton!
@IBAction func sendEmail(_ sender: UIButton) {
if !MFMailComposeViewController.canSendMail() {
print("Mail services are not available")
let ComposeVC = MFMailComposeViewController()
ComposeVC.mailComposeDelegate = self
ComposeVC.setToRecipients(["jwelch@ussunsolar.com"])
ComposeVC.setSubject("New Support Ticket")
ComposeVC.setMessageBody(CustomerName.text!, isHTML: false)
self.present(ComposeVC, animated: true, completion: nil)
}
func mailComposeController(controller: MFMailComposeViewController,didFinishWithResult result:MFMailComposeResult, error: NSError?) {
// Check the result or perform other tasks.
// Dismiss the mail compose view controller.
controller.dismiss(animated: true, completion: nil)
}
}
}