Sunday, January 8, 2012

Add Twitter Support To Your iPhone App In 5 Steps

Do you know how easy it is to give your users Twitter support in your app. This works like the email function in iOS apps – you will be able to present your user with a model view that is pre-populated with content that will become a tweet that will appear in your user's timeline.

This is what you need to do to add Twitter support to your iOS app:
  • Add Twitter framework
  • Import Twitter.h
  • Instantiate TWTweetComposeViewController
  • Set initial text, images and URLs
  • Present TWTweetComposeViewController in a model view controller

Here is an IBAction that I coded that implements this Twitter functionality.

-(IBAction)tweetTweet:(id)sender {     NSLog(@"%i", [TWTweetComposeViewController canSendTweet]);     TWTweetComposeViewController *tweeter = [[TWTweetComposeViewController alloc] init];     [tweeter setInitialText:self.myTextField.text];     [self presentModalViewController:tweeter animated:YES]; }