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>@implementationViewController
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_EXTERNNSString*constSLServiceTypeTwitter;SOCIAL_EXTERNNSString*constSLServiceTypeFacebook;SOCIAL_EXTERNNSString*constSLServiceTypeSinaWeibo;SOCIAL_EXTERNNSString*constSLServiceTypeTencentWeibo;SOCIAL_EXTERNNSString*constSLServiceTypeLinkedIn ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access