ios - Xcode swift 发送带截图的邮件?

标签 ios swift email

如何将 View Controller 的屏幕截图附加到邮件中?我已经有了发送邮件的代码...

@IBAction func SendMail(sender: AnyObject) {
    let picker = MFMailComposeViewController()
    picker.mailComposeDelegate = self
    picker.setCcRecipients(["xx@xx"])
    picker.setSubject("xxx" + " " + itemName.text! + "-" + itemEtage.text! + "-" + itemRaum.text!)
    picker.setMessageBody("xx" + " " + itemNow.text! + " " + "xxx", isHTML: true)

    presentViewController(picker, animated: true, completion: nil)
}

最佳答案

亲爱的,请引用以下代码

您可以将 MFMailComposer 与文件附件一起使用

使用 MFMailComposeViewController 在电子邮件正文中添加图像

 import MessageUI

func composeMail() {

    let mailComposeVC = MFMailComposeViewController()

    mailComposeVC.addAttachmentData(UIImageJPEGRepresentation(UIImage(named: "emailImage")!, CGFloat(1.0))!, mimeType: "image/jpeg", fileName:  "test.jpeg")

    mailComposeVC.setSubject("Email Subject")

    mailComposeVC.setMessageBody("<html><body><p>This is your message</p></body></html>", isHTML: true)

    self.presentViewController(mailComposeVC, animated: true, completion: nil)

}


文件作为附件

@IBAction func sendEmail(sender: UIButton) {
    //Check to see the device can send email.
    if( MFMailComposeViewController.canSendMail() ) {
        println("Can send email.")

        let mailComposer = MFMailComposeViewController()
        mailComposer.mailComposeDelegate = self

        //Set the subject and message of the email
        mailComposer.setSubject("Have you heard a swift?")
        mailComposer.setMessageBody("This is what they sound like.", isHTML: false)

        if let filePath = NSBundle.mainBundle().pathForResource("swifts", ofType: "wav") {
            println("File path loaded.")

            if let fileData = NSData(contentsOfFile: filePath) {
                println("File data loaded.")
                mailComposer.addAttachmentData(fileData, mimeType: "audio/wav", fileName: "swifts")
            }
        }
        self.presentViewController(mailComposer, animated: true, completion: nil)
    }
}

关于ios - Xcode swift 发送带截图的邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35719346/

相关文章:

android - 缺少 64 位支持/缺少推送通知授权电话

objective-c - 如何从代码中选择 UICollectionView 的项目/单元格

ios - 从 XIB 添加的 Swift ScrollView 根本不可滚动

linux - 无法使用 exim 发送 html 电子邮件

google-apps-script - 在 Google Apps 脚本中创建电子邮件 - 无法创建 ä、ö、ü 等特殊字符

linux - shell 脚本 - 需要根据上面的输出将邮件发送到特定的 id

ios - 无法将目标添加到 UIButton

html - HTML 表格中的文本在 WKWebview 中是错误的可点击 "event"

ios - UITextField 数据未上传到 firebase

swift - 如何防止 Swift 的 UITextField 中出现空白或空格?