只是试图允许用户发送电子邮件。在单击“联系人”按钮的那一刻,它会将我带到黑屏而不是显示 mailComposers。
调试器响应
2018-05-14 11:10:59.465952-0400 应用程序 [2333:757177] 无法在 (UIButton) 上设置 (keyPath) 用户定义的检查属性:[setValue:forUndefinedKey:]:此类不符合键值编码关键keyPath。
但是,这只发生在使用 SWReveal 函数从左向右滑动菜单时。从下面删除代码时,所有其他功能都可以正常工作。只有在使用下面的代码时,才会在按下“按钮接触”时给我黑屏。
import Foundation
import UIKit
import MessageUI
class SendEmailVC: MFMailComposeViewController, MFMailComposeViewControllerDelegate
{
@IBAction func Send_Tapped(_ sender: Any)
{
if MFMailComposeViewController.canSendMail()
{
contact()
let mailComposeViewController = configureMailController() //FIXED √
self.present(mailComposeViewController, animated: true, completion: nil)
}
else
{
showMailError()
}
}
func configureMailController() -> MFMailComposeViewController
{
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self
mailComposerVC.setToRecipients(["testing@gmail.com"])
mailComposerVC.setSubject("Hello")
mailComposerVC.setMessageBody("How are you doing?", isHTML: false)
return mailComposerVC
}
/*
* DON'T EDIT THE CODE BELOW.
*/
func showMailError()
{
let sendMailErrorAlert = UIAlertController(title: "Email failed to send", message: "Your device fail to send the email", preferredStyle: .alert)
let dismiss = UIAlertAction(title: "Dale", style: .default, handler: nil)
sendMailErrorAlert.addAction(dismiss)
self.present(sendMailErrorAlert, animated: true, completion: nil)
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?)
{
controller.dismiss(animated: true, completion: nil)
}
}