我根据Swift Guide完成了MFMailComposeViewController()的常规设置
但是当我运行这个时,电子邮件会暂时显示,消失,我收到错误消息“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(["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)
}}
答案 0 :(得分:0)
这是xcode模拟器中的已知错误。它应该在您的设备上正常工作。
答案 1 :(得分:0)
您的代码是正确的。 MFMailComposeViewController
组件只能在iOS simulator
的{{1}}中进行测试。
如果您在device
中查看此Thread,问题就会在Apple Developer Forums
中显示,但仍然没有任何解决方法。