美文网首页iOS-swift
swift5 - 用户反馈(发送邮件)

swift5 - 用户反馈(发送邮件)

作者: promise96319 | 来源:发表于2019-07-14 15:53 被阅读0次
    // XXXViewController
    var controller: MFMailComposeViewController?
    
    func feedback() {
        if MFMailComposeViewController.canSendMail(){
            controller = MFMailComposeViewController()
            //设置代理
            controller?.mailComposeDelegate = self
            //设置主题
            controller?.setSubject("Feedback")
            //设置收件人
            controller?.setToRecipients(["lancexianghui@gmail.com"])
            //设置抄送人
            controller?.setCcRecipients([])
            //设置密送人
            controller?.setBccRecipients([])
            //设置邮件正文内容(支持html)
            controller?.setMessageBody("Please type here your issue or question:", isHTML: false)
            present(controller!, animated: true, completion: nil)
        } else {
            // 用户未建立邮箱账号,只有建立了邮箱账号才可发送邮件
            MessageManager.share.showMessage(theme: .warning, title: "Can't send mail on your device",  body: "Please setup an email account on the device.")
        }
    }
    
    // 代理 - 关闭邮件页面
    extension XXXViewController: MFMailComposeViewControllerDelegate {
        func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
            controller.dismiss(animated: true, completion: nil)
        }
    }
    
    

    相关文章

      网友评论

        本文标题:swift5 - 用户反馈(发送邮件)

        本文链接:https://www.haomeiwen.com/subject/mhtikctx.html