How to send audio file with image and caption in iMessage app for iOS 10?
<p>I am creating iMessage app and trying to send audio or video file to other user.</p>

<p>Video file works and looks fine but its not working as expected with audio file.</p>

<p>My current code is:</p>

<pre><code>let destinationFilename = mp3FileNames[i]
let destinationURL =  docDirectoryURL.appendingPathComponent(destinationFilename)

if let conversation = activeConversation {

    let layout = MSMessageTemplateLayout()
    layout.image = UIImage.init(named: "audio-x-generic-icon")
    layout.mediaFileURL = destinationURL
    layout.caption = selectedSongObj.name

    let message = MSMessage()
    message.layout = layout
    message.url = URL(string: "emptyURL")

    conversation.insert(message, completionHandler: nil)


    return
}
</code></pre>

<p>Looks like <code>layout.mediaFileURL = destinationURL</code> is not adding any file into message.</p>

<p>And when I try to send file with above code.It looks like shown below:</p>

<p><a href="https://i.stack.imgur.com/ezXpy.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/ezXpy.gif" alt="enter image description here"></a></p>

<p>It looks fine but there is no audio to play but if I try this way:</p>

<pre><code>let destinationFilename = mp3FileNames[i]
let destinationURL =  docDirectoryURL.appendingPathComponent(destinationFilename)

if let conversation = activeConversation {

    conversation.insertAttachment(destinationURL!, withAlternateFilename: nil, completionHandler: nil)
    return
}
</code></pre>

<p>And result with above code is:</p>

<p><a href="https://i.stack.imgur.com/vuOC9.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/vuOC9.gif" alt="enter image description here"></a></p>

<p>I can play audio for that message because it's there. But problem with that message is I can not attach any image or caption with it.</p>

<p>How can I attach image and audio file into same message.</p>

<p>And if possible instead of image can I add GIF?</p>

<p>Any help would be much appreciated, Thank you.</p>