Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 13, Custom Image, title and subtitle in the presented UIActivityViewController

I would like to know if there is any way to customise the image, title and subtitle of presented UIActivityViewController in iOS 13?

enter image description here

like image 292
Sattar Avatar asked Jan 10 '20 15:01

Sattar


1 Answers

I have found a solution using UIActivityItemSource

UIActivityItemSource have this protocol activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata?which we can use to set image title and subtitle for our UIActivityViewController

This is an example:

 public func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? {
    let metadata = LPLinkMetadata()

    metadata.title = "My title" // Preview Title

    // Set image 

        metadata.imageProvider = NSItemProvider(object: image)
        metadata.iconProvider = NSItemProvider(object: image)
        metadata.url = urlImage

   // Set URL for sharing 
        metadata.originalURL = myUrl // Add this if you want to have a url in your share message.

    return metadata
}

And this is the result: I have my custom image and title.

enter image description here

like image 68
Sattar Avatar answered Sep 17 '22 18:09

Sattar