1

只是试图允许用户发送电子邮件。在单击“联系人”按钮的那一刻,它会将我带到黑屏而不是显示 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)
}

}

4

2 回答 2

4

请使用代码快速打开邮件,扩展名如下。

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

}

于 2018-05-13T09:20:52.110 回答
0

这是修复黑屏问题的新更新代码。更近了 1 步。但是现在我在按下发送按钮时收到来自 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)
    }
}
于 2018-05-14T19:04:51.923 回答