Friday, October 23, 2015

Socialize through iOS Apps


Hi all,

Almost every app these days wants to socialize through Twitter, Facebook etc. and share there experience or contents of the apps.

With every changing iOS the process of Integration keeps on changing.
From Basic Authentication to Graph API to SLComposeViewController

Since iOS 8.0 we are using SLComposeViewController as Twitter and Facebook accounts are by default added with OS & you just need to setup the account.

So let's start...

1) Start by creating a single view based sample app


2) Name project as



3) Project navigator will look like this after adding Social .framework



4) Add following components in your storyboard file. 
A text field that takes input from user and buttons to share via Facebook and Twitter 




5) Now lets dig in some code by importing the social framework


6) Add text field and connect IBOutlet



7) Sending tweet on button click



How it works : 
 a) First of all we check the availability of twitter account on the device/simulator
 b) Create object of SLComposeViewController for service type Twitter
 c) Text to be shared : setInitialText method
 d) URL to be shared : addURL
 e) Image to be shared : addImage
 f) After setting required values we present the view controller


8) Sharing on facebook on button click




How it works :
 a) First of all we check the availability of facebook account on the device/simulator
 b) Create object of SLComposeViewController for service type Facebook
 c) Text to be shared : setInitialText method
 d) Image to be shared : addImage
 e) After setting required values we present the view controller

Now try this and see the result 
:)