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

1

15

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.

Snelling answered 22/8, 2016 at 7:34 Comment(0)
P
8

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

Photoelasticity answered 26/8, 2016 at 7:11 Comment(6)
If I cant then audio will look ugly.Snelling
You can hope that this is a temporary limitation. As iOS 10 is still in beta, things can change.Photoelasticity
You can file a bug report / feature request if you think the ability is lacking.Bottrop
Can you please refer iMessage app name "chatterbird"? He does the same thing.Impudent
@SohilR.Memon I've looked at this Chatterbird app and was so frustrated because it DID seem like they figured it out. HOWEVER! if you carefully tap the green message outside of the 'play' button it opens full screen and you'll see at the top the system generated file name and it is actually a .mp4 file. So my guess is, they couldnt get it to work either and their solution/hack was to create a video file JUST to send an m4a audio file. The video portion just shows the play button for the first frame and blank green screens for the rest.Spy
I have an open Radar for mediaFileUR not working correctly (without the image property set) on MSMessageTemplateLayout and it was marked as a duplicate of 27308860 and still open as of Nov 1st. The documentation really makes it seem like you should be able to send an m4a file using the template so you can set Caption and Subcaption, I hope they do fix it.Spy

© 2022 - 2024 — McMap. All rights reserved.