7

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)
         }
     }
}
masaldana2
  • 635
  • 9
  • 20

1 Answers1

2

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)
        }
masaldana2
  • 635
  • 9
  • 20
  • Is there somewhere on the forums you could link me to that someone from Apple told you to use insertAttachment instead? I have insertAttachment working as well, but would like to use MSMessageTemplateLayout if it is possible, since I'd like to send a caption with it. – naomimichiko Aug 16 '16 at 22:14
  • 1
    via the bug reporter "Apple Developer Relations20-Jul-2016 04:01 PM You are trying to insert a MSMessage with the Template’s MediaURL set to an Audio file. The only Media types that are supported as MSMessage backgrounds are kUTTypeImage and KuTTypeMedia. You should be using MSMessage’s insertAttachment API to insert an Audio file instead. I am successfully able to use the insertAttachment API to insert MP3, WAV and M4a. Please let us know whether the issue is resolved for you by updating your bug report." – masaldana2 Aug 16 '16 at 23:24
  • 2
    my response: according to the .mediaFileURL documentation site it says that "audio files, it shows a graphical representation of the audio’s waveform." they didnt respond send some coins – masaldana2 Aug 16 '16 at 23:25
  • yeah the documentation definitely makes it seem like you can use mediaFileURL for audio files :/ thanks – naomimichiko Aug 17 '16 at 15:09