单击发送按钮之前的联系人按钮时出现黑屏

Getting a black screen when clicking the contact button prior to the send button

只是试图让用户发送电子邮件。单击按钮 "contact" 时,我进入黑屏而不是显示 mailComposers。

调试器响应

2018-05-14 11:10:59.465952-0400 App[2333:757177] 无法设置 (keyPath) 用户定义检查 属性 在 (UIButton): [setValue:forUndefinedKey :]:此 class 与键 keyPath 的键值编码不兼容。

但是,只有在使用 SWReveal 函数从左向右滑动菜单时才会出现这种情况。从下面删除代码时,所有其他功能都可以正常工作。仅当使用下面的代码时,才会在按下 "button contact" 时给我黑屏。

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

}

请使用代码打开 swift 中的邮件,扩展名如下。

extension SendEmailVC: MFMailComposeViewControllerDelegate {

func contact() {

    if !MFMailComposeViewController.canSendMail() {
        ROAlert.warningAlertUnderNavigation(ROConstants.More.kNoMailConfigured, onView: self.view)
        return ()
    }
    let composeVC = MFMailComposeViewController()
    composeVC.mailComposeDelegate = self
    composeVC.setToRecipients([ROConstants.More.kContactEmail])
    // Present the view controller modally.
    self.present(composeVC, animated: true, completion: nil)
}

//MARK: - MFMailComposeViewControllerDelegate

func mailComposeController(_ controller: MFMailComposeViewController,
    didFinishWith result: MFMailComposeResult, error: Error?) {
    // Check the result or perform other tasks.

    // Dismiss the mail compose view controller.
    controller.dismiss(animated: true, completion: nil)
}

}

这是修复黑屏问题的新更新代码。更近 1 步。但是现在我在按下发送按钮时收到来自 showMailError() 的错误消息。这是调试器显示的内容

2018-05-14 15:03:40.474236-0400 projectName[2510:835559] [MC] 过滤邮件 sheet bundle 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)
    }
}