iosuiactivityviewcontrollerios13

iOS13 share sheet: how to set preview thumbnail when sharing UIImage


The new share sheet on iOS13 shows a preview/thumbnail of the item being shared on its top left corner.

When sharing an UIImage using an UIActivityViewController I would expect a preview/thumbnail of the image being shared to be displayed there (like e.g. when sharing an image attached to the built in Mail app), but instead the share sheet is showing my app's icon.

What code/settings are required to show a thumbnail of the image being exported in the share sheet?

I have set up the UIActivityViewController as follows:

let image = UIImage(named: "test")!
let activityVC = UIActivityViewController(activityItems: [image], applicationActivities: nil)                          
activityVC.popoverPresentationController?.sourceView = self.view                            
self.present(activityVC, animated: true, completion: nil)

Solution

  • Just pass the image urls to UIActivityViewController not the UIImage objects. For example:

    let imageURLs: [URL] = self.prepareImageURLs()
    let activityViewController = UIActivityViewController(activityItems: imageURLs, applicationActivities: nil)
    self.present(activityViewController, animated: true, completion: nil)
    

    You can see that the image name and the image properties are shown in the top of the UIActivityViewController. Hope it helps!