I am new to audio and video assets in Swift and am trying to enable users to share audio or video using ActivityViewController.
To share text and images I can do:
var bestContent0 = "Check out this restaurant..."
bestContent1 = Image(named:myImage)
let activityViewController = UIActivityViewController( activityItems: [bestContent0], applicationActivities: nil)
activityViewController.modalPresentationStyle = .formSheet
present(activityViewController, animated: true)
In that case, when you launch the activityViewController it recognizes the type of the content. For example, with an image it will give you the option Copy, Save Image, Assign to Contact, Print, Add to Shared Album etc.
From what I can gather in the case of an audio, you are supposed to pass the local Url to the audio as the activityItem, not the actual audio file
However, when I do that, the activityViewController does not recognize the type of content and does not offer any options. It also shows the url address as opposed to an icon. I have also tried sharing a player item based on the url but that also does not seem to recognize the format
There is an alternative to activityViewController called UIDocumentInteractionController, however, Apple says this is:
A view controller that previews, opens, or prints files with a file format that your app can’t handle directly.
I would think an iosApp should be able to handle an audio file…but maybe I am missing something.
What is the recommended way to share an audio (mp3 file) located in the documents directory?
Thanks for any suggestions.