How to post to Facebook and Twitter using Social Framework

It is extremely simple to bring up Facebook and Twitter Sheets in your app using the Social Framework.

Once imported you can create a new instance of SLComposeViewController, initialise it with text, an image and a URL, and present it modally from your own view controller.

Screen Shot 2013-12-06 at 18.50.57

You don’t have to specify anything other than which service you’d like to use, in which case the presented sheet will be blank. Here we bring up a tweet sheet (i.e. Post to Twitter dialogue):

And here we specify all three values for a post to Facebook:

Available service types are

– SLServiceTypeFacebook
– SLServiceTypeTwitter
– SLServiceTypeSinaWeibo
– SLServiceTypeTencentWeibo

You can test if a service is available using the isAvailableForService method (which always returns YES on the simulator, and only gives accurate results on a real device):

Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.

Add your voice!