Sharing Images With UIActivityViewController & UIActivityItemSource

Derek Kim
8 min readOct 17, 2023

Hello, this is Derek!

Today I wanted to write about implementing a button to share an images with others. By the end of this blog, you will now understand how to implement sharing functionality using UIActivityViewController and UIActivityItemSource. See image example below for a visual example:

Suppose you have an app that has an image. I’ve gone ahead and created my own simple UI view for this particular demo.

When the button is pressed, I want to show the share view that was shown earlier. Let’s see what exactly we want to show on the sharing view.

We first have an image thumbnail on the left, with a title text, and a subtitle that consists the image’s file type and file size.

Let’s start with the basic implementation example. To share an image, we must present UIActivityViewController and pass the data to activityItems parameter.

public init(activityItems: [Any], applicationActivities: [UIActivity]?)

It takes an array of [Any], which means we can also pass other types such as String, Int or any other valid…

--

--