【问题标题】:PerformSegue after getting an email result获得电子邮件结果后执行Segue
【发布时间】:2018-12-16 22:54:08
【问题描述】:
    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

【问题讨论】:

  • completion handler 中尝试performSeguedismiss
  • @Willjay,谢谢。这很好用。我在下面为其他人发布了一个代码示例。

标签: ios swift uiviewcontroller segue


【解决方案1】:

感谢威利杰:

显示他有效的评论的代码示例: 这将执行以下操作: - 如果发送了邮件,我们会显示一个警报,说它是成功的,然后当用户在警报上按“确定”时执行Segue() 到主屏幕:

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

          }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-05
    • 2019-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-14
    相关资源
    最近更新 更多