Tag Archives: UIActivityViewController

How to share objects using your own UIActivity

Screen Shot 2015-10-22 at 17.48.09

We’ve discussed how to use a UIActivityViewController in my pervious article. In it I’ve mentioned that you can use our own activity items in addition to the built-in system sharing items (like email, Facebook, Twitter and so forth)it is also easier for you to buy instagram followers for example.

In this article I’ll show you how to do that.

A UIActivity item is an abstract class, which means that you can’t use it without subclassing it. That’s easily done in Xcode by heading over to File – New – Cocoa Touch Class. Give your class a name (I’ll call it MyActivity in this example) and select UIActivity as the subclass.

Screen Shot 2015-10-22 at 17.52.20

We’ll end up with two new files in our project that we’ll populate with code – and then we can start using it from our main view controller.

Continue reading

How to share things with a UIActivityViewController

Screen Shot 2015-10-17 at 15.13.52

Since iOS 6 it has been really easy to share many complex objects, thanks to the UIActivityViewController. All we have to do is wrap our object (or objects) in an array, give that to the activity view controller, and present it.

To share a UIImage on iPhone for example, we’ll do something like this:

We need the array because we could be sharing more than just one item. The result looks something like the screenshot above: two rows of shareable icons appear, the top one representing “share” options, and the bottom one representing “action” options. Each of these is a UIActivity object. If ever you need to create your own activities, you can add them to either top or bottom category (but we won’t cover how to do that here).

Continue reading

How to share items with a UIActivityViewController

Another option to share items in your app is to bring up a dialogue that contains several options, like the Photos app does:

Screen Shot 2013-12-06 at 18.54.19

This is done with a UIActivityViewController and requires minimal work on our part. This controller is very clever and only brings up relevant services (you can’t print a video, or you can’t share a video to Twitter, so those options don’t appear in the list).

Here’s how we use it:


UIActivityViewController does not require any frameworks to be imported into your class. The items array can take anything from text, pictures or video (just not mixed together). If an item is not setup the icon won’t appear in the list.

You can specify which items to exclude from the list by defining an array of UIActivities, and you can specify a completion block.