Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

15. Networking > Twitter

Twitter

Apple’s new Twitter framework offers a prebuilt tweet composition view controller as well as a simple request API that you can easily integrate into your applications. It makes tweeting a simple option that you can add to your code with very little programming.

Here’s basically everything you need to do in order to tweet. This method establishes a new tweet view controller, adds an image to it, sets its completion handler to dismiss, and presents it:

- (void) tweet: (id) sender
{
    TWTweetComposeViewController *tweeter =
       [[TWTweetComposeViewController alloc] init];
    [tweeter addImage:imageView.image];

    TWTweetComposeViewController __weak *twee = tweeter;
    tweeter.completionHandler =
    ^(TWTweetComposeViewControllerResult result){
        [[NSOperationQueue mainQueue] addOperationWithBlock:^(){
            TWTweetComposeViewController __strong *twong = twee;
            [twong dismissModalViewControllerAnimated:YES];
        }];
    };
    if (IS_IPAD)
        tweeter.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentModalViewController:tweeter animated:YES];
}


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint