ios - 未调用 MFMailComposeViewController didFinishWithResult
<p><p>我正在编写一个具有通用表单的应用程序,该表单会根据用户在表单中输入的内容进行调整和更改,然后他们会通过并回答表单中较低的问题,因此我在代码中进行了答案检查以使其工作,当用户单击提交时,邮件撰写 ViewController 加载正常,然后他们单击发送并发送电子邮件,但没有调用 didFinishWithResult 函数,这意味着 Composer 不会解雇。请看下面我的代码:</p>
<pre><code>@IBAction func Submit(sender: AnyObject) {
if SelectedTalkLabel.text! == "Safe Breaking Ground - Toolbox Talk" && ASwitch.on && BSwitch.on && DSwitch.on && !(CSwitch.on) || SelectedTalkLabel.text! == "Loading & Unloading Vehicles - Toolbox Talk" && ASwitch.on && BSwitch.on && CSwitch.on && !(DSwitch.on) || SelectedTalkLabel.text! == "Orteco - Toolbox Talk" && ASwitch.on && CSwitch.on && !(BSwitch.on) && !(DSwitch.on) {
let toRecipents = ["[email protected]"]
let emailTitle = "New ToolBox Talk Submission received!"
let messageBody = String(format: "")
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("cancelled")
self.dismissViewControllerAnimated(true, completion: nil)
case MFMailComposeResultFailed.rawValue:
print("failed")
AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
self.dismissViewControllerAnimated(true, completion: nil)
case MFMailComposeResultSaved.rawValue:
print("saved")
self.dismissViewControllerAnimated(true, completion: nil)
case MFMailComposeResultSent.rawValue:
print("sent")
self.dismissViewControllerAnimated(true, completion: nil)
default:
break
}
if SelectedTalkLabel.text! == "Safe Breaking Ground - Toolbox Talk" && !(ASwitch.on) || !(BSwitch.on) || !(DSwitch.on) || SelectedTalkLabel.text! == "Loading & Unloading Vehicles - Toolbox Talk" && !(ASwitch.on) || !(BSwitch.on) || !(CSwitch.on) || SelectedTalkLabel.text! == "Orteco - Toolbox Talk" && !(ASwitch.on) || !(CSwitch.on) {
let WrongAlert = UIAlertController(title: "Wrong Answer!", message: "You have selected the wrong answers, please go back and try again", preferredStyle: .Alert)
let WrongDismiss = UIAlertAction(title: "Okay", style: .Cancel, handler: {
(alert: UIAlertAction!) -> 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]