I have a requirement to share an:
- Image
- Text
- URL
I have the following apps installed on my device:
- SnapChat
- TikTok
When trying to share using the standard UIActivityViewController
code
private func launchActivityController(withItems items: [Any])
{
let activityViewController
= UIActivityViewController(activityItems: items,
applicationActivities: nil)
present(activityViewController, animated: true)
}
Here are my results when the items
array consists of the following:
- Image only: I can see all the 6 destinations + some others mentioned above
- Image + Text: I can see only IG, FB, Twitter and Mail but no snap and tik tok
- Image + URL: I can see Mail, FB, Twitter and Snap but no IG and TikTok
- Image + Text + URL: I can see Mail, FB, Twitter but no IG, Snap and TikTok
I have 2 questions:
1 - Is anyone aware some kind of documentation for the popular platforms (IG, Snap, TikTok) on what type of content they support with the UIActivityViewController
for example:
2 - And the more important question, Is it possible to prepare sharing data in different ways so that we can see every possible sharing destination in the UIActivityViewController
and then retrieve only the supported data type once the share destination is chosen
What I tried
I have tried what this answer suggested using UIActivityItemSource
like so:
extension CouponViewController: UIActivityItemSource
{
func activityViewControllerPlaceholderItem
(_ activityViewController: UIActivityViewController) -> Any
{
return UIImage()
}
func activityViewController
(_ activityViewController: UIActivityViewController,
itemForActivityType activityType: UIActivity.ActivityType?) -> Any?
{
return UIImage()
// I can't send a different type or an array of items
}
}
The issue is, I can only send one type, not an array of types. The type returned in activityViewControllerPlaceholderItem
cannot be different from itemForActivityType activityType
as well so it seems I can just return String, UIImage or URL.
When I return an array of different types (for example a UIImage, a String), nothing shows up in the share sheet, it is just blank.
Another interesting solution I tried was mentioned here where I created a custom type for each share type, one for URL, one for UIImage and one for String and then I initialize the activity controller like this
UIActivityViewController(activityItems: [ImageProvider(),
TextProvider(),
URLProvider()],
applicationActivities: nil)
However, I am back to square one as it again only shows me destinations that support all three types of content
Just a repeat of the question incase you got to the end:
Is it possible to prepare sharing data in different ways so that we can see every possible sharing destination in the UIActivityViewController
and then retrieve only the supported data type once the share destination is chosen
Thanks in advance