【问题标题】:Swift 4 - Segue to new ViewController after Email is sentSwift 4 - 发送电子邮件后转到新的 ViewController
【发布时间】:2018-07-03 00:24:09
【问题描述】:

在我的应用程序中,我有一个 MFMailComposeViewController。当 MFMailComposeViewController 呈现它自己时。当点击发送时,我需要它与新的 viewController 连接。当点击“发送”时会发生什么。新的视图控制器出现,然后 MFMailComposeViewController 重新出现。有人对此有解决方案吗?我需要做的就是在点击“发送”后转到新的 viewController。 谢谢。

导入 UIKit 导入 MessageUI

class ViewController: UIViewController, MFMailComposeViewControllerDelegate {

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

@IBAction func send(_ sender: Any) {
    let sendMailVC = configureMailController()
    if MFMailComposeViewController.canSendMail(){
        self.present(sendMailVC, animated: true, completion: nil)
    }
    else{
        showMailError()
    }
}

func configureMailController() -> MFMailComposeViewController{
    let mailComposerVC = MFMailComposeViewController()
    mailComposerVC.mailComposeDelegate = self
    mailComposerVC.setToRecipients(["clpowerpalletchecklist@gmail.com", "abeangoalie39@gmail.com"])
    mailComposerVC.setSubject("ForkLift #PP1 Issue")
    mailComposerVC.setMessageBody("Hi Mom", isHTML: false)

    return mailComposerVC
}

func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
    switch result {
    case .cancelled:
        print("canceled")
        break
    case .failed:
        print("big nope")
        break
    case .saved:
        print("saved")
        break
    case .sent:
        self.performSegue(withIdentifier: "by", sender: nil)
        break
    }
    controller.dismiss(animated: true, completion: nil)
}

func showMailError(){
    let sendMailErrorAlert =  UIAlertController (title:"Could not send Email to the following recipient", message: "Please notify your supervicer of the issue.", preferredStyle: .alert)
    let ok:UIAlertAction = UIAlertAction(title: "OK", style: .default){
        (_:UIAlertAction) in
        //self.performSegue(withIdentifier: "emailDone", sender: nil)
    }
    sendMailErrorAlert.addAction(ok)
    self.present(sendMailErrorAlert, animated: true, completion: nil)
}


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


}

【问题讨论】:

    标签: segue viewcontroller mfmailcomposeviewcontroller


    【解决方案1】:

    尝试使用带有dismiss(animated: true, completion: nil) 的弹出消息而不是 self.performSegue(withIdentifier: "by", sender: nil)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多