I am bringing up a share sheet for sharing a link on iOS13. By default, it will fetch the title and image at the top of the sheet from the shared URL, and I would like to overwrite both. I have the title ready, but the image is remote and needs to be fetched. Preferrably, I would like the share sheet with the title to show up instantly, and the remote image being loaded in afterwards.
I found out about a new method in UIActivityItemSource
that seems to do this, so I created a custom UIActivityItemSource
subclass:
@objc class CustomURLItemSource: NSObject, UIActivityItemSource {
...
func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
return shareURL
}
func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
return shareURL
}
@available(iOS 13.0, *)
func activityViewControllerLinkMetadata(_: UIActivityViewController) -> LPLinkMetadata? {
let metadata = LPLinkMetadata()
metadata.originalURL = shareURL
metadata.url = shareURL
metadata.title = "My custom title"
metadata.imageProvider = NSItemProvider(contentsOf: imageURL)
return metadata
}
}
Using this item source, my custom title will show up, but the image next to the title will just be the default safari icon. How does iOS expect me to provide the image or image url here?