如何将 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/