Title: HOW TO INTEGRATE TWITTER AND FACEBOOK SHARING IN IOS APP?
1WELCOME TO LOGINWORKS SOFTWARES
2HOW TO INTEGRATE TWITTER AND FACEBOOK SHARING IN
IOS APP?
- Hey folks, Today we will be going to learn more
about social sharing feature of iOS, As we all
know a few years back developers have to make use
of facebook and twitter API to provide the
sharing feature. - But later after the release of ios 6 Apple
provides a much easier way to share the post
directly without even make use of an API. With
the help of SocialSharing Library of iOS.
3SOCIAL FRAMEWORK After the introduction of iOS 6
version, a new framework arrives which is known
as Social Framework. This framework enables
users to integrate your app with any supported
social networking services. Currently, it
supports Facebook and Twitter. This framework
gives you an interface to interact with different
social media and it enables you from learning the
internals. Even you dont have to implement any
of the Twitter/Facebook APIs, how to handle
network connection, handle single sign-on, etc.
The social framework simplifies everything.
You just need to write a few lines of code to
bring up the composer and users can tweet/publish
a Facebook post on your app. The social framework
comes with a very handy class named
SLComposeViewController. The SLComposeViewControll
er class presents a standard view controller for
users to compose the tweet or Facebook post. This
also allows developers to preset the initial
text, attach images and also adding URL to the
post, If you want to implement the simple sharing
feature, this is the only class you need to know
and that we will go through today.
If youre not familiar with the
SLComposeViewController, this is what it looks
like within your app. So Lets get started now.
4 INITIAL SETUP
- Go to the Xcode and select create a new
application and after this Click on the
SingleViewApplication. - After this Name your application as Social
Sharing Application as mentioned in the image
below.
5IMPORT FRAMEWORK Now head to the framework
section of your Xcode and add the Social
Framework to your application as I mentioned
below.
6DESIGNING INTERFACE
Now we will be going to design the interface for
our application and to this, we need to add few
objects to our view controller. But first, we
will be going to create our own view and to do
this. Go to File -gt New -gt File -gt Cocoa Touch
Class -gt UIViewController . Then name the view
controller file as SocialViewController as shown
below.
7ESTABLISHING CONNECTION BETWEEN VARIABLES AND
ELEMENTS
Now we need to add few objects to our view
controller. UIView We will be going to add a
custom color to our view. I will be using Hexa
color 008040 for my design you can choose a
color of your choice. UILabel With the help of
this Label I am going to write a text to it which
is Social Sharing Buttons so that the design
looks better here. UIButtons We will be going
to use two buttons here so that we can add action
to them later to handle facebook and twitter
share feature. After doing all the objects
designing our view will looks similar to this.
8 As you can see that I have added two images to my
asset folder and using them to set an image on
buttons so that both of them looks different and
are identical. Now to make the connection between
the objects and view we need to drag and drop all
objects one by one to our viewcontroller.h
file. Drag the first button which is facebook
button and create an action of it. Now drag the
second button which is twitter button and create
an action to it as shown below.
9POINT TO REMEMBER
- It is important that your social media account
should be configured inside your iPhone settings
and if there is no account present in it then it
will going to show you two choice - with a custom alert either to choose to cancel or
to choose settings option as shown.
10CHOICE 2 If you choose Settings button then it wi
ll be going to redirect you to settings of your
device through which you can add the details to
your social media account and configure it from
there, So that next time if you re-run the
application then it can easily be going to update
the social media post through this application.
ADDING TWITTER SUPPORT Now its time to add
some functionality to Twitter so that we can
share our social media update using twitter
button also. Twitter is also one of the best ways
to share our feeling or some tweet using
twitter, iOS provides twitter support using its
SocialFramework similar to facebook.
STEP 1 We will be going to add the code inside
our twitter button so that we can use its action
to share our tweet on twitter profile.
First add your Twitter credentials into your
twitter setting inside your iPhone so that it
will not ask you, again and again, to add the
account to it. STEP 2 Add the following code to
perform the functionality of the twitter button
as shown below.
11ADDING IMAGE TO YOUR POST
12- As you can see that the image is attached to the
twitter post and you can add an image of your
choice into it. After adding the image the final
code should look like this - FINAL RUN
- Now if you run the final project after finishing
all the task performed earlier then your
application should look like this as shown
13- Looks Amazing Right!!
- After Successfully sharing your status it will be
going to show you the success message as
mentioned below.
14 ADDITIONAL LESSON
If you dont know how to create a custom alert
of your choice then I am adding the method to do
it below as we know that in iOS 9, The alert view
is depreciated and in the place of it we will be
going to use alert controller which contains the
updated code according to Apples
guidelines. First, Create an alert controller
object and add the title and message and alert
type to it.
15SUMMARY This is it, You have successfully made an
application that can help you share your status
on social media without even using any API and
with fewer efforts. As you can see from this tuto
rial, its quite easy to add Twitter and Facebook
supports using the Social Framework in iOS 6. If
youre building your app, there is no reason why
you shouldnt use the social features. With this
support, it adds values to your app and may boost
its popularity. The tutorial introduces the basic
s of Facebook and Twitter integration. You can
try to make a demo application and upload
multiple images to the social networks.
However, if you want to access more advanced
features such as display users Facebook email
and friend list, youll need to understand the
Facebook API. I hope you enjoy the tutorial about
the social framework. If you want more tutorial
related to this then let me know.
16 Thank you For Watching
Connect with This For More Inf
https//www.loginworks.com/blogs/
Call us 1-434-608-0184