O'Reilly logo

iOS 6 Programming Cookbook by Vandad Nahavandipoor

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2.11. Presenting Sharing Options with UIActivityViewController

Problem

You want to be able to allow your users to share content inside your apps with their friends, through an interface similar to that shown in Figure 2-35, using different sharing options available in iOS, such as Facebook and Twitter.

The activity view controller displayed on an iOS device

Figure 2-35. The activity view controller displayed on an iOS device

Solution

Create an instance of the UIActivityViewController class and share your content through this class, as we will see in the Discussion section of this recipe.

Note

The instances of UIActivityViewController must be presented modally on the iPhone and inside a popover on an iPad. For more information about popovers, refer to Recipe 2.27.

Discussion

There are many sharing options inside iOS 6, and all are built into the core of the OS. For instance, Facebook and Twitter integration is now an integral part of the core of iOS and you can share pretty much any content from anywhere you want. Third-party apps like ours can also use all the sharing functionalities available in iOS without having to think about the low-level details of these services and how iOS provides these sharing options. The beauty of this whole thing is that you mention what you want to share and iOS will pick the sharing options that are capable of handling the items that you want to share. For instance, if you want to share images and text, iOS will ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required