只是尝试允许用户发送电子邮件。在单击“联系人”按钮时,它会将我带到黑屏,而不是显示mailComposers。
调试器以
响应2018-05-14 11:10:59.465952-0400 App [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)
}
}
答案 0 :(得分:0)
以下是修复黑屏问题的新更新代码。靠近一步。但是现在我在按下发送按钮时从showMailError()收到错误消息。这是调试器显示的内容
2018-05-14 15:03:40.474236-0400 projectName [2510:835559] [MC]过滤包ID的邮件表帐户:projectName,来源帐户管理:1
import Foundation
import UIKit
import MessageUI
class SendEmailVC: UIViewController // MFMailComposeViewController: Caused black screen
{
@IBAction func SendButton_Tapped(_ sender: UIButton)
{
if MFMailComposeViewController.canSendMail()
{
let mailComposeVC = self.configureMailController()
self.present(mailComposeVC, animated: true, completion: nil)
}
else
{
self.showMailError()
}
}
func configureMailController() -> MFMailComposeViewController
{
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.setSubject("Hello")
mailComposerVC.setMessageBody("How are you doing?", isHTML: true)
mailComposerVC.setToRecipients(["<b>eddx544@gmail.com</b>"])
mailComposerVC.mailComposeDelegate = self
/*
* mailComposerVC.addAttachmentData( attachment: date,
mimeType: "String here",
fileName: "String here" )
*/
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: "Dismiss", style: .default, handler: nil)
sendMailErrorAlert.addAction(dismiss)
self.present(sendMailErrorAlert, animated: true, completion: nil)
}
}
extension SendEmailVC: MFMailComposeViewControllerDelegate
{
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?)
{
controller.dismiss(animated: true, completion: nil)
}
}