Twitter Integration in iOS

Twitter Integration in iOS

Lets assume you have developed a great application and now you want to make it “Social”. Facebook and Twitter are the two most popular social networking sites.

In this tutorial, we will learn how to deep integrate Twitter in your application. Before starting, I am assuming that you are familiar with the Objective C syntax and Xcode environment and have basic knowledge of iOS.

1. Frameworks – To Integrate with Twitter we will use the “Accounts” framework and the “Social” framework.You need to add these frameworks into your project. “Accounts” framework lets you to not worry about the OAuth implementation that Twitter requires.

2. Accounts in Settings – To check if the user already has an account in the Settings app use:

If the account is not already set in the Settings, we would need to take the user to the Settings page, which is not possible in iOS as it is a private API. Work around – When you try to access a Twitter account even when an account is not set in the settings, iOS presents user an alertView that no account is set in the Settings. It can then take user to the settings app to set the new account. We are going to use this as a workaround. To prompt user to go to the Settings page use:

3. Access the Account – Time to access the Account of the user: To access account, we first need to get an AccountStore Object. Then from the Account store we get the Account object as:

4. Request to Twitter API – Now to make a request to the twitter API we just need to create a SLRequest and add this account to the request. For example to simply get the home_timeline of the user you can use :

And thats it .. You can get the list of all the possible twitter requests at https://dev.twitter.com/docs/api/1.1

Have fun !!

Looking for a mobile solution with social media integration? Contact sales@innovationm.com

Leave a Reply