MFMailComposeViewController 出现一秒钟然后消失

MFMailComposeViewController appears for a second then disappears

我已经按照 Swift 指南

完成了 MFMailComposeViewController() 的常规设置

https://developer.apple.com/library/prerelease/ios/documentation/MessageUI/Reference/MFMailComposeViewController_class/

但是当我 运行 这样时,电子邮件会出现一瞬间,然后消失,我收到错误消息 "MailCompositionService quit unexpectedly"。

这里是完整的代码

import Foundation
import UIKit
import MessageUI

class ViewController: UIViewController, MFMailComposeViewControllerDelegate {

@IBAction func showEmail(sender: AnyObject) {

    let composeVC = MFMailComposeViewController()
    composeVC.mailComposeDelegate = self
    // Configure the fields of the interface.
    composeVC.setToRecipients(["address@example.com"])
    composeVC.setSubject("Hello!")
    composeVC.setMessageBody("Hello from California!", isHTML: false)

    // Present the view controller modally.
    self.presentViewController(composeVC, animated: true, completion: nil)
}

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

    switch result.rawValue {
    case MFMailComposeResultCancelled.rawValue:
        print("Mail cancelled")
    case MFMailComposeResultSaved.rawValue:
        print("Mail saved")
    case MFMailComposeResultSent.rawValue:
        print("Mail sent")
    case MFMailComposeResultFailed.rawValue:
        print("Mail sent failure: \(error!.localizedDescription)")
    default:
        break
    }
    controller.dismissViewControllerAnimated(true, completion: nil)
}}

这是 xcode 模拟器中的一个已知错误。它应该在您的设备上正常工作。

您的代码是正确的。 MFMailComposeViewController 组件无法在 iOS simulator 中测试,只能在 device.

中测试

如果您在 Apple Developer Forums 中查看这个 Thread 问题在 Apple Bug Report 中有一个票证,但仍然没有任何修复。