菜鸟教程小白 发表于 2022-12-11 16:42:24

ios - 未调用 MFMailComposeViewController didFinishWithResult


                                            <p><p>我正在编写一个具有通用表单的应用程序,该表单会根据用户在表单中输入的内容进行调整和更改,然后他们会通过并回答表单中较低的问题,因此我在代码中进行了答案检查以使其工作,当用户单击提交时,邮件撰写 ViewController 加载正常,然后他们单击发送并发送电子邮件,但没有调用 didFinishWithResult 函数,这意味着 Composer 不会解雇。请看下面我的代码:</p>

<pre><code>@IBAction func Submit(sender: AnyObject) {

    if SelectedTalkLabel.text! == &#34;Safe Breaking Ground - Toolbox Talk&#34; &amp;&amp; ASwitch.on &amp;&amp; BSwitch.on &amp;&amp; DSwitch.on &amp;&amp; !(CSwitch.on)    ||    SelectedTalkLabel.text! == &#34;Loading &amp; Unloading Vehicles - Toolbox Talk&#34; &amp;&amp; ASwitch.on &amp;&amp; BSwitch.on &amp;&amp; CSwitch.on &amp;&amp; !(DSwitch.on)    ||    SelectedTalkLabel.text! == &#34;Orteco - Toolbox Talk&#34; &amp;&amp; ASwitch.on &amp;&amp; CSwitch.on &amp;&amp; !(BSwitch.on) &amp;&amp; !(DSwitch.on) {


      let toRecipents = [&#34;[email protected]&#34;]
      let emailTitle = &#34;New ToolBox Talk Submission received!&#34;
      let messageBody = String(format: &#34;&#34;)

      let mc : MFMailComposeViewController = MFMailComposeViewController()

      mc.mailComposeDelegate = self


      mc.setToRecipients(toRecipents)
      mc.setSubject(emailTitle)
      mc.setMessageBody(messageBody, isHTML: false)

      self.presentViewController(mc, animated: true, completion: nil)

}

func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {

      switch result.rawValue {

      case MFMailComposeResultCancelled.rawValue:
            print(&#34;cancelled&#34;)
            self.dismissViewControllerAnimated(true, completion: nil)

      case MFMailComposeResultFailed.rawValue:
            print(&#34;failed&#34;)
            AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
            self.dismissViewControllerAnimated(true, completion: nil)

      case MFMailComposeResultSaved.rawValue:
            print(&#34;saved&#34;)
            self.dismissViewControllerAnimated(true, completion: nil)

      case MFMailComposeResultSent.rawValue:
            print(&#34;sent&#34;)
            self.dismissViewControllerAnimated(true, completion: nil)


      default:
            break

      }

      if SelectedTalkLabel.text! == &#34;Safe Breaking Ground - Toolbox Talk&#34; &amp;&amp; !(ASwitch.on) || !(BSwitch.on) || !(DSwitch.on)    ||    SelectedTalkLabel.text! == &#34;Loading &amp; Unloading Vehicles - Toolbox Talk&#34; &amp;&amp; !(ASwitch.on) || !(BSwitch.on) || !(CSwitch.on)    ||    SelectedTalkLabel.text! == &#34;Orteco - Toolbox Talk&#34; &amp;&amp; !(ASwitch.on) || !(CSwitch.on) {

            let WrongAlert = UIAlertController(title: &#34;Wrong Answer!&#34;, message: &#34;You have selected the wrong answers, please go back and try again&#34;, preferredStyle: .Alert)

            let WrongDismiss = UIAlertAction(title: &#34;Okay&#34;, style: .Cancel, handler: {
                (alert: UIAlertAction!) -&gt; Void in
            })

            WrongAlert.addAction(WrongDismiss)

            self.presentViewController(WrongAlert, animated: true, completion: nil)
    }
}
</code></pre>

<p>这类似于我在应用程序中使用的其他形式的代码,根本不使用戏剧。如果有人可以尝试帮助我解决这个问题,将不胜感激。干杯。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我遇到了同样的问题,并且正在寻找过去 2 天的修复程序,然后我自己找到了一个修复程序,你不会相信它是多么小。</p>

<p>在我的情况下,我正在展示 <code>MFMailComposeViewController</code> 的 ViewController (根据这个问题说“DetailsTableViewController”,根据这个问题,您的“提交”按钮存在)已经从其他一些 ViewController 呈现(比如“BaseViewController”)。</p>

<p>问题在于“DetailsTableViewController”的“<code>modalPresentationStyle</code>”,同时从 BaseViewController 呈现它。</p>

<p>当我将它从 '<code>UIModalPresentationFormSheet</code>' 更改为 '<code>UIModalPresentationPageSheet</code>' 时(就此而言,除了 '<code>UIModalPresentationFormSheet</code>' 之外的任何东西)问题得到解决,邮件 Controller 委托(delegate)方法开始照常触发。</p>

<p>注意:我已经在 'DetailsTableViewController' 中调用了以下方法(对于本示例),因此我使用的是哪个 '<code>modalPresentationStyle</code>' 对我来说并不重要。</p>

<pre><code>- (void)viewWillLayoutSubviews{
    ;
    self.view.superview.bounds = CGRectMake(0, 0, 1024, 768);
    self.view.superview.backgroundColor = ;
}
</code></pre>

<p>希望这也能解决您的问题。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 未调用 MFMailComposeViewController didFinishWithResult,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/37721463/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/37721463/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 未调用 MFMailComposeViewController didFinishWithResult