简体   繁体   English

MFMailComposeViewController出现一秒钟然后消失

[英]MFMailComposeViewController appears for a second then disappears

I have done the usual set up of the MFMailComposeViewController() as per Swift Guide 我已经按照Swift指南完成了MFMailComposeViewController()的常规设置

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

but when I run this then the email appears for a split second, disappears and I get the error message "MailCompositionService quit unexpectedly". 但是当我运行此命令时,电子邮件出现了一秒钟,消失了,并且出现错误消息“ MailCompositionService意外退出”。

here is the full code 这是完整的代码

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)
}}

This is a known bug in the xcode simulator. 这是xcode模拟器中的一个已知错误。 It should work fine on your device. 它应该可以在您的设备上正常工作。

Your code is correct. 您的代码是正确的。 The MFMailComposeViewController component can't be tested in the iOS simulator only in the device . MFMailComposeViewController组件只能在deviceiOS simulator无法测试。

If you look this Thread in Apple Developer Forums the problem has a ticket in Apple Bug Report but still without any fix. 如果您在Apple Developer Forums查看此主题 ,则该问题在Apple Bug Report有票证,但仍然没有任何修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM