Twitter Post
In iOS 6, the interface for letting the user construct a Twitter post is SLComposeViewController, part of the Social framework (superseding TWTweetComposeViewController and the Twitter framework). Twitter, together with Facebook and Weibo, are represented by constant strings. You’ll use a class method to learn whether the desired service is available; if it is, you can instantiate SLComposeViewController for that service and present it as a presented view controller.
Instead of a delegate, SLComposeViewController has a completionHandler. Set it to a block taking one parameter, an SLComposeViewControllerResult. In the block, dismiss the view controller.
Here’s a minimal example:
BOOL ok =
[SLComposeViewController
isAvailableForServiceType:SLServiceTypeTwitter];
if (!ok) return;
SLComposeViewController* vc =
[SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
if (!vc) return;
vc.completionHandler = ^(SLComposeViewControllerResult result) {
// could do something with result
[self dismissViewControllerAnimated:YES completion:nil];
};
[self presentViewController:vc animated:YES completion:nil];You can also, with the user’s permission, gain secure access to the user’s Twitter account information (or Facebook, or Weibo) through the ACAccountStore class (part of the Accounts framework). Using this, along with the SLRequest class, your app can construct and post a message directly, without passing through the message composition interface; see Apple’s ...
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