How to send audio file with image and caption in iMessage app for iOS 10?

2.4k views Asked by At

I am creating iMessage app and trying to send audio or video file to other user.

Video file works and looks fine but its not working as expected with audio file.

My current code is:

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
}

Looks like layout.mediaFileURL = destinationURL is not adding any file into message.

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

enter image description here

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

let destinationFilename = mp3FileNames[i]
let destinationURL =  docDirectoryURL.appendingPathComponent(destinationFilename)

if let conversation = activeConversation {

    conversation.insertAttachment(destinationURL!, withAlternateFilename: nil, completionHandler: nil)
    return
}

And result with above code is:

enter image description here

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.

How can I attach image and audio file into same message.

And if possible instead of image can I add GIF?

Any help would be much appreciated, Thank you.

1

There are 1 answers

6
nsinvocation On BEST ANSWER

Not necessary to use GIF, iMessage extensions supports also PNGand JPEG image formats. Recommended image size is 300x300 points at @3x scale.

If the MSMessageTemplateLayout's image property has a non-nil value then mediaFileURL property is ignored. So you can't send an image and an audio file at the same time. Docs