I would like to know if there is any way to customise the image, title and subtitle of presented UIActivityViewController in iOS 13?
Asked
Active
Viewed 5,085 times
7
-
1Did you figure this out? I've seen a few apps do and this I was wondering how they did it. – ian Feb 13 '20 at 14:04
-
@ian yes i did, I will answer to this question. – Sattar Feb 13 '20 at 17:36
1 Answers
11
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.

Sattar
- 393
- 5
- 18
-
5FYI You can kinda 'hack' the subtitle by using a file URL. `metadata.originalURL = URL(fileURLWithPath: "My custom subtitle")` – Shaps Aug 10 '20 at 10:48
-
1
-
3What object do you pass for image? For me the image is seen with extra white spaces around. – Sayalee Pote Feb 19 '21 at 11:01
-
1
-
1Thanks. I figured the issue I was facing. Do you have any idea why we cannot see - 'Add to Reading list' option even when we are sharing a link through the app? Struggling to find what is the issue. – Sayalee Pote Feb 22 '21 at 07:22
-
2@SayaleePote What was the issue that you figured out? I'm getting white space around my image as well… Thanks! – Erika Electra Nov 30 '21 at 11:13
-
1
-
@ArtemZaytsev I don't remember the exact fix but make sure your image is a simple UIImage object that is assigned to 'let image = UIImage(named: "test")' – Sayalee Pote Oct 09 '22 at 23:52
-
Does it work in iOS Simulator?, for some reason I don't see thumb image despite setting it. – Evgeny Karkan Jan 30 '23 at 03:22