MFMailComposeViewController出现一秒然后消失

问题描述 投票:0回答:2

我根据Swift Guide完成了MFMailComposeViewController()的常规设置

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

但是当我运行它然后电子邮件显示一瞬间,消失,我收到错误消息“MailCompositionService意外退出”。

这是完整的代码

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(["[email protected]"])
    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)
}}
ios swift email mfmailcomposeviewcontroller
2个回答
0
投票

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


0
投票

你的代码是正确的。 MFMailComposeViewController组件不能仅在iOS simulator中的device中进行测试。

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

© www.soinside.com 2019 - 2024. All rights reserved.