Tuesday, October 2, 2012

Posting Data to Facebook from iOS 6

In this post we will learn how to post data on facebook using iOS 6.
For this tutorial you will need Xcode 4.5.

Apple has introduced a new framework called as the social framework with the help of which you can connect to social networking sites like facebook, twitter, weibo.

Apple has not released any documentation on this framework may be because it’s still under some clause of apple and may be in future they will release the entire class reference for this framework although a small part of their documentation is release which you may read here.

In this tutorial I will show you how you can post data using this new framework by apple to your facebook wall feeds.

So let’s get down to business

Step 1: For this demo I will be creating a single view xcode application with one button and on the touch of this button we will display the in build pop up for facebook posting. Connecting to facebook with the new framework is very much similar to the twitter framework in IOS 5.

So create a single view project and add the social framework to it.

Step 2: After adding the social framework add create a function in the .h file of your view controller class that will be called on the button.

And here’s a view at the implementation part of the function

Code Explanation: First we are checking that if the SLComposeViewController is available for connections with the service of facebook.

In the second line of code I am asking the SLComposeViewController that I want him to present the view for facebook.

In the third line I am setting the text

And in the last line I am pushing the SLComposeViewController in front of the user to post the required data.

Also just like we used to perform the check in the twitter framework in iOS 5 the same check is performed here to check if the data is successfully posted on facebook or not.

Step 3: Before running this application you have to perform a minor setting in the iOS simulator and that setting would be to configure your facebook account with it in the settings sections else you will get the pop up like the one given below

So configure your facebook account by selecting the settings icon and from there you have to select the facebook option.

Step 4: Now once the configuration is done successfully all you have to do is run the application.

Step 5: After running the application you will see the view like this

If you see the pop up saying success then it means that the data is posted on your facebook wall go ahead and check it out.

Similarly you can post URL and Images on your wall,

Now when you run the application you will get a view which looks like the one given below

You may go to your facebook account and check the data that you have just posted.

You may download the sample code from here.

If you have any sort of queries then do let me know regarding that will help you out.

Until then Happy iCoding and have a great Day.


  1. how to change album of image on Facebook?
    i m tried but it remain ios :(
    and how to work with Facebook API by creating Facebook App like u r previous Facebook tutorial

  2. @Shrimant : Currently i am going through the process and will post it up as soon as i get the way of doing this or what i think is may be apple might have changed their process of posting data on facebook, although facebook API is available and you may use that.

  3. This is really wonderful example for posting on the wall.. Thnk u very much for that... Will You please tell me that How to get comments of any particular user or how to comment on any pic or like any pic

  4. Thanks dear ! :)