MFMailComposeViewController didFinishWithResult未被调用

时间:2016-06-09 09:06:33

标签: ios delegates uipopovercontroller mfmailcomposeviewcontroller dismiss

我正在编写一个带有通用表单的应用程序,根据用户输入表单的内容进行调整和更改,然后他们会通过并回答表单中较低的问题,以便我在代码中检查答案以使其工作,当用户点击提交邮件撰写视图控制器加载正常时,他们然后点击发送和电子邮件发送但不调用didFinishWithResult函数意味着作曲家不解散。请参阅下面的代码:

@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 = ["example@abc.com"]
        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)
    }
}

这类似于我在应用程序中使用的其他形式的代码,完全没有戏剧性。如果有人能帮我解决这个问题,我将不胜感激。欢呼声。

2 个答案:

答案 0 :(得分:0)

我遇到了同样的问题并且正在寻找过去2天的修复,然后我找到了自己的修复方法,你不会相信它有多么轻微。

在我的情况下,我提交MFMailComposeViewController的视图控制器(比如说' DetailsTableViewController'根据这个问题你的提交按钮出现了)从其他视图控制器呈现(比如说' BaseViewController')。

问题在于modalPresentationStyle' ' DetailsTableViewController'从BaseViewController中呈现它。

我从' UIModalPresentationFormSheet'更改了它的那一刻到' UIModalPresentationPageSheet' (就此而言,除了' UIModalPresentationFormSheet')之外的任何问题都得到了解决,邮件控制器委托方法也照常启动。

注意:我已经在' DetailsTableViewController'中调用了以下方法。 (对于这个例子)所以对我来说并不重要的是modalPresentationStyle'我正在使用。

- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    self.view.superview.bounds = CGRectMake(0, 0, 1024, 768);
    self.view.superview.backgroundColor = [UIColor clearColor];
}

希望这也可以解决您的问题。

答案 1 :(得分:-1)

你厌倦了交换:

 self.dismissViewControllerAnimated(true, completion: nil)

controller.dismissViewControllerAnimated(true, completion: nil)