Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 {
             print(error)
         }
     }
}
like image 859
masaldana2 Avatar asked Jun 20 '16 04:06

masaldana2


People also ask

How do I enable audio on iMessage?

To send a voice message on iPhone, press and hold the record button next to the iMessage text box. You can listen to a voice message by opening it in the Messages app and tapping the media file. To stop voice messages from expiring two minutes after the recipient plays them, remove the limit in Settings.


1 Answers

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 {
            print(error)
        }
like image 59
masaldana2 Avatar answered Oct 14 '22 14:10

masaldana2