Game Development Reference
In-Depth Information
Figure 9-12. Tweeting from Belt Commander
In Figure 9-12 , we see the built-in component for tweeting on iOS. On the top, we have the place
where the 120 characters can be typed. To the right, there is a paperclip holding a Safari icon. This
indicates that a link was attached to this tweet. The user can also add a location, cancel, or send the
tweet. The code to populate this view with default values and display them is shown in Listing 9-6.
Listing 9-6. RootViewController.m (tweetButtonClicked:)
- (IBAction)tweetButtonClicked:(id)sender {
SLComposeViewController* twitterSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[twitterSheet setInitialText:@"Check out this iOS game, Belt Commander!"];
[twitterSheet addURL:[NSURL
URLWithString:@" http://itunes.apple.com/us/app/belt-
commander/id460769032?ls=1&mt=8 " ]];
[self presentViewController:twitterSheet animated:YES completion:^(void){
NSLog(@"twitter done");
}];
}
In Listing 9-6, we see the tweetButtonClicked : task of the class RootViewController . This task
is called when a user clicks the Tweet button. To display the Twitter component, we simply
create a new SLComposeViewController and indicate that we are interested in the Twitter
service. After specifying the initial text and attaching a URL, we simply pass twitterSheet to
presentModalViewController . If we want to know whether the tweet was sent, we can assign a block
to the value completionHandler of twitterSheet .
Of course, not every user will have Twitter set up on his or her device. As a developer, you want to
be able to test this, which turns out to be as simple as the code in Listing 9-7.
Search WWH ::




Custom Search