如何将录制的音频附加到电子邮件?在SWIFT [英] How to attach recorded audio into email? in SWIFT
本文介绍了如何将录制的音频附加到电子邮件?在SWIFT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个应用程序记录wav的语音类型并发送电子邮件。我想将录制的文件作为附件添加到电子邮件中?这里是sendEmail代码
I've an app that record voices type of "wav" and send emails ,too. I want to add that recorded file into the email as attachment?? here is sendEmail code
func sendemail(email: String){
if( MFMailComposeViewController.canSendMail() ) {
println("Can send email.")
let mailComposer = MFMailComposeViewController()
mailComposer.mailComposeDelegate = self
//Set the subject and message of the email
mailComposer.setSubject("Voice Note")
mailComposer.setMessageBody("my sound", isHTML: false)
mailComposer.setToRecipients([email])
// the app doesn't go trough this IF STATEMENT
if let filePath1 = NSBundle.mainBundle().pathForResource("fahad", ofType: "wav") {
println("File path loaded.")
if let fileData = NSData(contentsOfFile: filePath1) {
println("File data loaded.")
mailComposer.addAttachmentData(fileData, mimeType: "audio/wav", fileName: "fahad")
}
}
self.presentViewController(mailComposer, animated: true, completion: nil)
}
}
推荐答案
从评论中解答答案,为其他#Programmers添加答案:
Solved the answer from the comments, adding answer for other #Programmers :
func sendemail(email: String){
if( MFMailComposeViewController.canSendMail() ) {
println("Can send email.")
let mailComposer = MFMailComposeViewController()
mailComposer.mailComposeDelegate = self
//Set the subject and message of the email
mailComposer.setSubject("Voice Note")
mailComposer.setMessageBody("my sound", isHTML: false)
mailComposer.setToRecipients([email])
if let docsDir = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as? String {
var fileManager = NSFileManager.defaultManager()
var filecontent = fileManager.contentsAtPath(docsDir + "/" + fileName)
mailComposer.addAttachmentData(filecontent, mimeType: "audio/x-wav", fileName: fileName)
}
self.presentViewController(mailComposer, animated: true, completion: nil)
}
}
这篇关于如何将录制的音频附加到电子邮件?在SWIFT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文