收到电子邮件结果后执行PerformSegue

时间:2018-12-16 22:54:08

标签: ios swift uiviewcontroller segue

    When sending an email:


        if MFMailComposeViewController.canSendMail()
            {
                let mail = MFMailComposeViewController()
                mail.mailComposeDelegate = self
                // the set to receipient
                // is always this email
                // since this is the owners email
                mail.setSubject("ORDER CONFIRMATION RODEO'S CATERING")
                mail.setToRecipients(["rodeoscatering2018@gmail.com"])
                mail.setMessageBody( m_information_for_body , isHTML: false)
                self.present(mail, animated: true)
            }


         func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?)
         {
          // In here I am checking if it is sent
         case .sent:
            do
            {
               print("sent")

                controller.dismiss(animated: true, completion: nil)
                // and then doing a performSegue below...
                // performSegue(withIdentifier....)
            }

          }

我知道标识符不是问题,所有标记都在那里。我看到了打印信息。但是不幸的是,发生的所有事情是,当出现电子邮件提示时,我按发送,然后电子邮件控制器被关闭(这很好),并带我到当前屏幕,并显示打印消息,但是performSegue却没有。不会发生。

我本质上希望它到发生.sent案件的地方,然后返回主页

Swift 4.2和最新的xCode 10.1

1 个答案:

答案 0 :(得分:0)

贷记给Willijay:

显示有效的他的注释的代码示例: 这将执行以下操作: -如果发送了邮件,则我们将显示一条警报,指出已成功,然后当用户在警报上按“确定”时,将performSegue()返回主屏幕:

func go_back_home() -> Void
{
    let title   = "Confirmation Order Status"
    let message = "Message was sent. Check email for a copy"

    let alert = UIAlertController(
        title: title,
        message: message,
        preferredStyle: .alert)

    alert.addAction(UIAlertAction(title:"OK", style: .default, handler:
    {
        action in self.performSegue(withIdentifier: "order_info_back_to_home_page", sender: self)

    }))

    self.present(alert, animated: true)
}

然后我们使用go_back_home()函数的方式是:

func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?)
         {
          // In here I am checking if it is sent
         case .sent:
            do
            {
               print("sent")

                controller.dismiss(animated: true, completion: go_back_home)
            }

          }
相关问题