Swift 4 - 发送电子邮件后切换到新的 ViewController



在我的应用程序中,我有一个MFMailComposeViewController。当 MFMailComposeViewController 自行呈现时。我需要它在点击发送时切换到新的视图控制器。当点击"发送"时会发生什么。新的视图控制器出现,然后 MFMailComposeViewController 重新出现。有人对此有解决方案吗?我需要它做的只是在点击"发送"后切换到新的视图控制器。 谢谢。

导入 UIKit 导入消息用户界面

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.
}

}

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

最新更新