我遇到了一點代碼錯誤。我對此很陌生,我正在努力教導自己。我在網上找到了大部分答案,但似乎無法找到有關此特定問題的任何信息。我想在應用程序內發送電子郵件,但每次按下電子郵件按鈕時,MFMailViewController都不會出現。這就像我的UIButton不工作。但我知道我將它作爲IBAction。這是我的代碼到目前爲止。任何幫助深表感謝。UIButton不會顯示MFMailViewController
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(["[email protected]"])
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)
}
}
}
你在模擬器中測試這個嗎?這隻適用於實際的iPhone設備。 –