3

In my iMessage App I'm trying to send a remote video file. From the documentation I can read that the property mediaFileURL in MSMessageTemplateLayout object should be the right point where to set the URL

The media file URL must be a file URL

This is how I'm creating the MSMessage instance

let message = MSMessage()
message.shouldExpire = false

let layout = MSMessageTemplateLayout()
layout.mediaFileURL = self.videoURL

message.layout = layout

But, when I call the insertMessage method, I can't get the correct message entity (no video included)

conversation.insertMessage(message, completionHandler: nil)

I've read somewhere (not an official source) that the URL should be a local URL, is that true?

Thanks in advance for any help

ADDING

I'm even trying to download the content and set the local URL, but I'm having the same behavior

This is the quick implementation I tried

let fileURL = storeDirectory.URLByAppendingPathComponent("video-file.mov")!

_ = try? NSFileManager.defaultManager().removeItemAtPath(fileURL.path!)

Alamofire.download(.GET, self.videoURL) { _, _ -> NSURL in
    return fileURL
}.response { _, _, _, error in
    print("Error: \(error)")
    layout.mediaFileURL = fileURL
    print("File URL: \(fileURL)")
    message.layout = layout
    completion(.success(message))
}

Of course, the error is nil and the file path is a valid local path that references a valid video file (I can reproduce it by going at that path)

SOLVED:

For anyone is experiencing this problem, please make sure to download the media file firstly. It's not mentioned in the documentation, but it's mandatory. Then, even if in the documentation the audio file is mentioned, a normal mp3 file doesn't work at all. Still don't know what's the specification regarding the audio file.

After that, make sure your result is fine: sending the media file in the MSMessageLayout means that it's muted and you've to handle the detail view when it's tapped. Consider to use the insertAttachment method of MSConversation instead.

Luca D'Alberti
  • 4,749
  • 3
  • 25
  • 45
  • How exactly do you mean you have to handle the detail view when its tapped? – naomimichiko Nov 01 '16 at 14:35
  • 1
    The `MSMessage` with an audio/video file inside aren't played on the iMessage transcript view. When the receiver (or the sender) tap on the message, you receive a call in your iMessage app view controller as a normal message @naomimichiko – Luca D'Alberti Nov 01 '16 at 14:36
  • Ok so you handle playing the audio in the didSelect: method? – naomimichiko Nov 01 '16 at 14:37
  • 1
    No, I just used the `insertAttachment` method and I'm not using the `MSMessage` instance at all. In this way, the media file is handled as a normal media file sent via iMessage @naomimichiko – Luca D'Alberti Nov 01 '16 at 14:38
  • I see, I see. Thanks, I have gotten it to work using insertAttachment as well but my client wants to be able to use the MSMessageTemplateLayout to display a title and subtitle :/ Was hoping you had gotten a way to send an audio file with mediaFileURL to work. Thank you! – naomimichiko Nov 01 '16 at 14:40
  • layout.mediaFileURL = self.videoURL does it autoplay the videos? – Idrees Ashraf Jul 26 '17 at 06:40
  • Can either Luca or Naomi please expand your use of insertAttachment and how that is received? I'm sending with insertAttachment and don't see how to get the data on the receiver side. – Andy Dent Dec 23 '18 at 09:42

0 Answers0