Swift 3,iOS10.3 - 电子邮件窗口打开,但不关闭

时间:2017-04-19 16:22:37

标签: ios swift email window

我可以通过按下按钮在iOS 10.3中打开一个电子邮件窗口,但我无法关闭它(取消和发送不要关闭它)。由于我是Swift的新手,我假设我的代码中没有看到明显的错误:)

import UIKit
import MessageUI
import Foundation

class settings: UIViewController, MFMailComposeViewControllerDelegate {

    override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func sendEmailButtonTapped(_ sender: Any) {
    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
    mailComposerVC.setToRecipients(["email@email.com"])
    mailComposerVC.setSubject("Subject of email")
    return mailComposerVC
}
func showSendMailErrorAlert() {
    let sendMailErrorAlert = UIAlertView(title: "Could Not Send Email", message: "Your device could not send Email.  Please check Email configuration and try again.", delegate: self, cancelButtonTitle: "OK")
    sendMailErrorAlert.show()
}

func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {
    controller.dismiss(animated: true, completion: nil)
}

}

0 个答案:

没有答案