这是示例代码:
import UIKit import MessageUI class ViewController: UIViewController, MFMailComposeViewControllerDelegate { @IBAction func showEmail(sender : AnyObject) { var emailTitle = "Test Email" var messageBody = "This is a test email body" var toRecipents = ["a.nakhimov@gmail.com"] var mc: MFMailComposeViewController = MFMailComposeViewController() mc.mailComposeDelegate = self mc.setSubject(emailTitle) mc.setMessageBody(messageBody, isHTML: false) mc.setToRecipients(toRecipents) self.presentViewController(mc, animated: true, completion: nil) } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func mailComposeController(controller:MFMailComposeViewController, didFinishWithResult result:MFMailComposeResult, error:NSError) { switch result.value { case MFMailComposeResultCancelled.value: NSLog("Mail cancelled") case MFMailComposeResultSaved.value: NSLog("Mail saved") case MFMailComposeResultSent.value: NSLog("Mail sent") case MFMailComposeResultFailed.value: NSLog("Mail sent failure: %@", [error.localizedDescription]) default: break } self.dismissModalViewControllerAnimated(true) // self.dismissViewControllerAnimated(true, completion: nil) } }
当我按下按钮时,功能 showEmail 被执行并显示用于发送电子邮件的表格。如果单击“发送”,则一切正常-发送邮件,然后执行函数 mailComposeController 。NSLog显示标签 “邮件已发送”, 并再次出现初始屏幕。
如果我在发送邮件的对话框中,单击 “取消” 按钮,则对话框不会消失,函数 mailComposeController 不起作用,两个按钮-“发送”和“取消”,变为灰色,因此保持不变。
怎么了
似乎是iOS 8中的错误。在Objective-C中也存在相同的问题。