O'Reilly logo

iOS 7 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

11.11. Integrating Social Sharing into Your Apps

Problem

You want to provide sharing capabilities in your app so that your user can compose a tweet or a Facebook status update on her device.

Solution

Incorporate the Social framework into your app and use the SLComposeViewController class to compose social sharing messages, such as tweets.

Discussion

The SLComposeViewController class is available in the Social framework and with the Modules feature in the LLVM compiler. All you have to do to start using this framework is import its umbrella header file into your project like so:

#import "ViewController.h"
#import <Social/Social.h>

@implementation ViewController

As Apple adds new social sharing options to the SDK, you can query the Social framework to find out, at runtime, which one of the services is available on the device that runs your app. Because the particular services vary from device to device, you should not try to use one until you make sure it is running. In order to query iOS for that, you need to use the isAvailableForServiceType: class method of the SLComposeViewController class. The parameter that you pass to this method is of type NSString, and here is a list of some of the valid parameters that you may pass to this method:

SOCIAL_EXTERN NSString *const SLServiceTypeTwitter;
SOCIAL_EXTERN NSString *const SLServiceTypeFacebook;
SOCIAL_EXTERN NSString *const SLServiceTypeSinaWeibo;
SOCIAL_EXTERN NSString *const SLServiceTypeTencentWeibo;
SOCIAL_EXTERN NSString *const SLServiceTypeLinkedIn ...

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