【问题标题】:Stuck in New Message email client in iOS App卡在 iOS 应用程序中的新消息电子邮件客户端
【发布时间】:2017-01-09 10:16:59
【问题描述】:

我正在尝试实现 MessageUI 和 MFMailComposeViewController 以便在我的应用程序中发送电子邮件。一切似乎都很好,只是一旦我开始了这个过程,我实际上就无法离开邮件客户端。如果我点击发送,它会发送,然后什么都不做(不返回应用程序)。如果我点击取消,它不会删除草稿和套件(或再次返回应用程序)。

import UIKit
import MessageUI

class ContactFormViewController: UITableViewController, MFMailComposeViewControllerDelegate {

...

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    switch indexPath.item{
        case 0:
            followOnEmail()
        default:
            break
    }
}

private func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
    controller.dismiss(animated: true, completion: nil)
}

func followOnEmail(){
    if !MFMailComposeViewController.canSendMail(){
        print("Mail services are not available")
        return
    }

    let composeVC = MFMailComposeViewController()
    composeVC.mailComposeDelegate = self

    // Configure the fields of the interface.
    composeVC.setToRecipients(["info@cegainnovations.com"])
    composeVC.setSubject("")
    composeVC.setMessageBody("Please enter your message below.", isHTML: false)

    if MFMailComposeViewController.canSendMail(){
        // Present the view controller modally.
        self.present(composeVC, animated: true, completion: nil)
    }
    else{
        self.showSendMailErrorAlert()
    }
}

...

func showSendMailErrorAlert(){
    let alertController = UIAlertController(title: "Could Not Send Email", message: "Your device could not send email. Please check e-mail configuration and try again.", preferredStyle: .alert)
    let defaultAction = UIAlertAction(title: "Close", style: .default, handler: nil)
    alertController.addAction(defaultAction)
    present(alertController, animated: true, completion: nil)
}

}

【问题讨论】:

    标签: ios email


    【解决方案1】:

    Swift 3 稍微改变了 API。 改变

    private func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
    

    func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-21
      • 1970-01-01
      • 2015-09-26
      • 1970-01-01
      • 1970-01-01
      • 2020-05-08
      相关资源
      最近更新 更多