Search code examples
iosswiftuiviewcontrollerwhatsappuiactivityviewcontroller

Share Audio (MP3) to WhatsApp with text using UIActivityViewController


I'm trying to share an audio file (MP3) using UIActivityViewController. While the audio file is shared successfully, the accompanying text message I'm adding does not appear in the message. It only sends the MP3 file without the text.

Here is the code I'm using:

let message = "some message"
let itemsToShare: [Any] = [message, mediaURL]

let activityViewController = UIActivityViewController(activityItems: itemsToShare, applicationActivities: nil)

activityViewController.excludedActivityTypes = [
    .addToReadingList,
    .assignToContact,
]

self.rootViewController?.present(activityViewController, animated: true, completion: nil)

How can I ensure that both the audio file and the text message are shared together, specifically for WhatsApp? Any help or suggestions would be appreciated!


Solution

  • How can I ensure that both the audio file and the text message are shared together, specifically for WhatsApp?

    You cannot ensure it. As you know if you've done this in the opposite direction, the receiving app gets an "envelope" which it must "open" to retrieve its contents. How WhatsApp does that is up to WhatsApp. It is not in your control.