Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 13 Share Sheet: Changing subtitle/item description

The new iOS 13 share sheet provides a nice header that shows the context of the item being shared.

enter image description here

I haven't been able to figure out how to change the item description though. I've used activityViewControllerLinkMetadata function which partially gives me what I need (changing title & icon), but originalURL, which is responsible for showing the item description, only accepts URL and every string has to be escaped if we create a URL from string (space to %20, for example).

@available(iOS 13.0, *)
        func activityViewControllerLinkMetadata(_: UIActivityViewController) -> LPLinkMetadata? {
            let metadata = LPLinkMetadata()
            metadata.title = song.title

            if let data = song.artistNames.data(using: .utf8) {
                let url = URL(dataRepresentation: data, relativeTo: nil)

                metadata.originalURL = URL(dataRepresentation: data, relativeTo: nil)

                if let image = image {
                    metadata.iconProvider = NSItemProvider(object: image)
                }
            }
            return metadata
        }

App Store and Music app can do this - has anyone figured this out?

like image 626
Jagoan Neon Avatar asked Mar 06 '20 12:03

Jagoan Neon


1 Answers

This is really silly, but this is how to do it.

metadata.originalURL = URL(fileURLWithPath: "whatever description you want to put")

And as a note, you don't have to create the file/folder itself.

like image 53
Jagoan Neon Avatar answered Oct 18 '22 18:10

Jagoan Neon