2016-01-25 94 views
0

我也做了MFMailComposeViewController(通常的設立)按斯威夫特指南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) 
}} 

回答

0

這是在Xcode模擬器一個已知的bug。它應該在你的設備上正常工作。

+0

感謝你的回答 - 我想我會變得瘋狂 - 因爲我遵循了蘋果開發者網站上的確切說明。 – kangarooChris

0

您的代碼是正確的。僅在device中才能在iOS simulator中測試MFMailComposeViewController組件。

如果你看這ThreadApple Developer Forums該問題有Apple Bug Report門票,但仍然沒有任何修復。

相關問題