小编RVJ*_*RVJ的帖子

在Swift 3.0迁移后不调用MFMailComposeViewControllerDelegate方法

我的应用程序具有电子邮件撰写功能,它在Swift 2.2上运行完美.最近我将代码迁移到Swift 3.0并坚持这个问题.在下面分享我的代码段:

import MessageUI

class ViewController: UIViewController,     MFMailComposeViewControllerDelegate {
 func sendEmail() {
    if MFMailComposeViewController.canSendMail() {
      let mail = MFMailComposeViewController()
      mail.mailComposeDelegate = self
      mail.setToRecipients(["someone@somewhere.com"])
      mail.setSubject("Sending you an in-app e-mail...")
      mail.setMessageBody("<p>You're so awesome!</p>", isHTML: true)
      self.present(mail, animated: true)
    } else {
        //  handle failure
    }
  }

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

    controller.dismiss(animated: true)
  }

 @IBAction func mailClicked(_ sender: AnyObject) {    
    sendEmail()
  }
 }
Run Code Online (Sandbox Code Playgroud)

我已将mailComposeDelegate设置为self,将_放入委托方法并尝试搜索时找到的所有解决方案.但无法解决问题.

任何帮助是极大的赞赏.

ios mfmailcomposer swift3

1
推荐指数
1
解决办法
517
查看次数

标签 统计

ios ×1

mfmailcomposer ×1

swift3 ×1