Monday, October 17, 2011

iOS 5 Twitter Integration HelloWorld Tutorial

Edit: I just noticed that Apple provided much better sample code which can be found here: Apple Sample Code

In this tutorial we will demonstrate some new Twitter features in iOS 5.

 1. Create a new "Single View Application" called "TwitterHelloWorld".

 2. Add the Twitter Framework to your new project.

3. Go to the "TwitterHelloWorldViewController.h" file and copy and paste the following. 

4. Go to the "TwitterHelloWorldViewController.m" file and implement the following like below. The most important thing is to remember to "#include " in either (.h/.m) files. 

The Twitter framework provides a class called "TWTweetComposeViewController". To use this class you must do four things: 1) Checks for service availability 2) Creates a view controller 3) Supplies a completion handler 4) Presents Modally. 

5. Go to the MainStoryboard file and create a drag a button and connect it to the MainViewController. Connect the drag the button to the view controller and select the "presentTweetSheet:". 

6. Start the simulator and if you haven't signed into your Twitter account it will prompt you to. If you're logged in a tweet sheet will pop-up and you will be able to type text. Below is the screenshot of after I posted the tweet. 

7. The sample code (which is heavily inspired by the Apple Demo) provides some other methods can you can use. If you're ever lost refer to the header files.


Dan said...
This comment has been removed by the author.
Peter Druska said...


your post is very helpful to me. But I have memory leak on this line of code:

_tweetSheet = [[TWTweetComposeViewController alloc] init];

Is your code clean off memory leaks? Thank you.

Peter Druska said...
This comment has been removed by the author.