I am currently using UIActivityViewController to share an url to other apps. This part works fine.
But when I'm sharing to an app like iMessage, Whatsapp or Mail. I would like to add a string.
Example:
Sharing -> airdrop: https://www.google.com
Sharing -> iMessage: "Hi there, checkout this cool website: https://www.google.com"
I tried to do it by adding both an Url object and a String into the UIActivityViewController like so:
let url = URL(string: "https://www.google.com)
let text = "Hi there, checkout this cool website: \(url)"
let items: [Any] = [url, text]
let controller = UIActivityViewController(
activityItems: items,
applicationActivities: nil)
DispatchQueue.main.async{self.present(controller, animated: true, completion: nil)}
^not the actual code, but enough to draw a picture
This does work with Airdrop, it opens the url.
It also works in Mail, it uses the string containing the url.
It doesn't work however in iMessage. iMessage takes both and combines them like so:
https://www.google.com Hi there, checkout this cool website: https://www.google.com
Does anyone have any suggestions for me to keep the functionality for Airdrop/Mail etc. But for it to also work on iMessage?
Use a UIActivityItemSource. The UIActivityItemSource is told the identifier of the requesting process, so you can refrain from handing the URL to Messages and hand it just the string, which is sufficient.