我希望你很好。MFMailComposeViewController不會關閉(iOS10)
我對Swift很陌生。我使用iOS10 SDK在XCode 8.0上構建了一個iOS應用程序。我試圖添加允許用戶發送電子郵件到預先配置的電子郵件地址的功能。當點擊發送按鈕時,MFMailComposeViewController正常打開,用戶可以通過其添加的郵件帳戶發送或取消。點擊發送實際上通常會發送電子郵件,但是MFMailComposeViewController在發送郵件或點擊取消按鈕後不會關閉。請幫忙!
感謝
import UIKit
import MessageUI
class EmailHelpdesk_ViewController: UIViewController, MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//Email Subject and Body text fields.
@IBOutlet var helpdesk_email_subject: UITextField!
@IBOutlet var helpdesk_email_body: UITextView!
//Helpdesk (Submit Button - Config)
@IBAction func helpdesk_email_send(_ sender: AnyObject) {
let HDsubjectText = helpdesk_email_subject.text
let HDbodyText = helpdesk_email_body.text
MFMailComposeViewController to be called.
let mail_controller_compose = MFMailComposeViewController()
mail_controller_compose.mailComposeDelegate = self
mail_controller_compose.setToRecipients(["[email protected]"])
mail_controller_compose.setSubject(HDsubjectText!)
mail_controller_compose.setMessageBody(HDbodyText!, isHTML: false)
self.present(mail_controller_compose, animated: true, completion: nil)
}
func mailComposeController(controller: MFMailComposeViewController,
didFinishWithResult result:MFMailComposeResult, error: NSError?) {
controller.dismiss(animated: true, completion: nil)
}
}
}
按照慣例,方法/函數和變量名稱應該是駝峯式的。例如,不是'helpdesk_email_send',而是使用'helpdeskEmailSend'。 – Adrian