MFMailComposeViewController in Swift does not dismiss

时光总嘲笑我的痴心妄想 提交于 2019-11-29 06:38:13

Seems to be bug in iOS 8. Same problem exist in Objective-C also.

You're trying to dismiss self instead of the MFMailComposeViewController (which isn't self).

Replace:

self.dismissModalViewControllerAnimated(true)

with:

controller.dismissViewControllerAnimated(true, completion: nil)

in the delegate method.

Bug has been resolved. Everything is working as expected in iOS 8.1+ and Xcode 6.1+

The following fires and works fine

extension MainViewController: MFMailComposeViewControllerDelegate {
    func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {
        switch result.value {
        case MFMailComposeResultCancelled.value:
            NSLog("Mail cancelled")
        case MFMailComposeResultSaved.value:
            NSLog("Mail saved")
        case MFMailComposeResultSent.value:
            NSLog("Mail sent")
        case MFMailComposeResultFailed.value:
            NSLog("Mail sent failure: %@", [error.localizedDescription])
        default:
            break
        }
        self.dismissViewControllerAnimated(true, completion: nil)
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!