亲爱的请参考下面的代码
您可以使用MFMailComposer与文件附件
添加图像
extension UIView {
func screenShot() -> UIImage {
UIGraphicsBeginImageContextWithOptions(bounds.size, opaque, UIScreen.mainScreen().scale)
let contextRef = UIGraphicsGetCurrentContext()
CGContextTranslateCTM(contextRef, 0, 0)
layer.renderInContext(contextRef!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}
您可以使用此:使用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)
}
}
你需要更清楚的问题,究竟是什么问题?你有截图吗?你知道如何将图像转换为数据吗?你知道如何附加文件吗?你研究了这些主题吗?这个问题太广泛了。 – Wain
@slevin,请参阅并尝试此解决方案进行屏幕保护 - http://stackoverflow.com/a/29592307/5593725和http://stackoverflow.com/a/25445629/5593725 –
嗨,谢谢..我需要截取屏幕截图并将其附加到带有一个按钮的新邮件。 – slevin