masaldana2 masaldana2 - 1 year ago 286
iOS Question

How to Load audiofile into MMessage ios 10?

so I been playing around the new xcode 8 beta and I'm able to load an image into the .image property but I had not succeed to load an audio file with the .mediaFileURL property.
here's my

var message = MSMessage()
var template = MSMessageTemplateLayout()

viewDidLoad() {
if let filePath2 =
Bundle.main().pathForResource("synth", ofType: "wav") {
let fileUrl = NSURL(string: filePath2)
let URL2 = fileUrl as! URL
template.mediaFileURL = URL2

message.layout = template

guard let conversation = activeConversation else {

fatalError("Expected a conversation") } conversation.insert(message,
localizedChangeDescription: nil) { error in
if let error = error {

Answer Source

According to bug reporter I should use the insertAttachment API to insert MP3, WAV and M4a.

conversation.insertAttachment(fileUrl, withAlternateFilename: "fileAudio") { error in
        if let error = error {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download