Tutorials

Introducing in iOS 6 is a brand new tweet sheet, which is part of the new Social Framework. With this sheet, it is easy to implement sending tweets form inside your app. In this tutorial we will choose a photo from the device library and we will tweet a message including this photo.

Update: Mar 14, 2017. The rewritten version in Swift for iOS 10.2 and Xcode 8.2.1 is available here.

Open Xcode and create a new Single View Application. For product name, use TwitterDemo and then fill out the Organization Name, Company Identifier and Class Prefix fields with your customary values. Make sure only iPhone is selected in Devices, and that the Use Storyboards is deselected and Use Automatic Reference Counting checkboxes are selected (Unit Tests will not be necessary for this project).

To implement tweeting from your app, we need the social framework go to the project settings and add the Social.framework

Let's create the User Interface. Go to viewController.m , drag a ImageView and two buttons to the view. Select the imageView and in the attributes inspector give the view a mode of "Aspect Fit". The view should look like this.

In ViewController.m, Create the following outlet property and IBAction methods in the @interface section.

We create a SLComposeViewController object, which embeds the tweet sheet and all functionality.

The initial twwet text is set, also the selected image is added to the tweet.

The tweet sheet is presented.

If the twitter account isn't set up, we display an alert view.

We now must now implement the ability to show the Image Picker library of the device. This is made possible with the imagePickerController object. Our view controller must conform to the UIImagePickerControllerDelegate and UINavigationControllerDelegate protocol. Change the @interface line in