Share on Facebook0Share on Google+0Share on Reddit0Share on LinkedIn0Tweet about this on Twitter

How To Integrate Facebook Login in Mobile Application?

As of November 2 of this year, there are 1.79 billion users of Facebook.

And though we are already hearing that the network’s popularity is fading as millennials and Gen Z folks migrate to other social networking apps, Facebook will still remain the world’s most popular social network for the next few years (or even decades?).

And that’s exactly why most apps these days offer social media integration and authentication for users.

Admit it, typing your email and pass, then opening the email app, clicking that account validation link and logging in with your credentials is cumbersome. While Facebook login is fast and efficient from the user perspective.

And there’s data to prove that.

Saavn, a digital music app and Skyscanner, have seen a 65% and 100% growth in their user base after integrating Facebook login.

In fact, different businesses see different benefits from implementing this integrations:

  • Songkick mentioned that people who connected via Facebook Login bought 7% more tickets on average.
  • Lifesum spotted at 20% increase in retention rates after implementing Facebook Login.
  • eDoctor’s app witnessed a 39% growth in user registration after adding this option.

In general, the majority of product owners featured in the case studies point out that 70-80% of their users prefer to use Facebook login over other options.

And you always need to follow the users’ lead if you want to succeed with your business. So, on to practicalities!

How To Implement Facebook Login for iOS

The easiest way to integrate a Facebook login in iOS application (or Android, for that matter) is to use Facebook SDK (software development kit). This will allow you to:

  • Authenticate people through their Facebook credentials
  • Share content from your app to Facebook
  • Log in events in your app
  • Read and write to Graph API.

Facebook provides a great overview explaining all of these benefits and more. Go check it for starters.

It is important to note that Facebook does have certain platform policies. The most important being the permissions. When you integrate Facebook login, you may need ask for three permissions – public profile, email, and user friends. Anything beyond this will require that you submit your app for Facebook review.

Now, onto the integration!

Step 1: Facebook QuickStart Tool

  1. Register as a Developer with Facebook – this is a two-click process of providing you name, company name, title, and a box to check that you agree to Facebook’s platform policies. As soon as you submit this, you have permission to add Facebook login integration for iOS or Android.
  2. You will then be asked to select your platform – iOS, Android, or another one.
  3. Once you have made that selection, you will begin the process of registering your app – an existing one or a new one you are or have just developed.
  4. Now you need to complete the process by creating an app ID (the next page of the process) and submit.
  5. You will be prompted to download the Facebook SDK for iOS or Android, and then you are ready to move on to the other steps of the process. For iOS specifically, Facebook integration in Swift is highly desirable.

Step 2: Add SDK to the Project

Now you need to add the SDK to your app project in Xcode. You simply open your app’s Xcode project, and drag the frameworks files into the Frameworks group (if you don’t have a frameworks group, add one) of Xcode’s Project Navigator.

You will want to choose “Create groups for any added folders,” and be sure to deselect the “Copy items into destination group’ folder.” Open Xcode’s “Build Settings” tab and add ~/Documents/FacebookSDK to your Framework Search Paths setting.

Step 3: Configure Xcode Project

In the previous step, you opened Xcode’s “Build Settings” tab in your project.

Now you are going to configure the Xcode. Here are the steps:

  • In Xcode, secondary-click the project’s .plist file and choose “Open As ->Source Code”
  • Facebook will now give you a snippet to insert in the file body. This snippet will be found in the Facebook instructions for “Configure Xcode Project”
  • Replace “fb(your-app-id)” with your Facebook app ID
  • Enter it as this example: fb17564. If you have forgotten your app ID – check the Facebook App Dashboard
  • Replace (your-app-id) with yours
  • Replace (your-app-name) with the name you specified for your app
  • Replace (human-readable reason for photo access) with the reason you need photo access

Step 4: Connect App Delegate

Now you need to connect your appDelegate to FBSDKApplicaiontDelegate object. Facebook provides the code for you to do this in its instructions.

Step 5: Add App Events

SDK is now installed and configured. The best way to test it is to add App Events. There are 14 pre-defined events with SDK – everything from “level achieved” if it is a game, or “added to cart” if the app is an e-commerce one.

You will also be able to define custom events that relate to the unique features of your app. For example, you have a hotel booking app and you want to know which hotels are the most popular with the users. You can set that as a custom event.

FAQ and Troubleshooting

Facebook also provides a section in its tutorial for FAQ’s and troubleshooting. This is a pretty comprehensive library to help you sort out the “bugs”, which occurred while setting up your login. If you have followed the SDK instructions carefully, you should not have issues though 🙂

Facebook Access Tokens

When anyone uses Facebook Login, the app will get an access token that will give temporary access to Facebook API’s. These tokens will identify a user, an app, or a page, and will also have information about expiration and the app that generated the token in the first place.

  • User Tokens: These are the most common tokens. They are required when an app calls upon an API to access a person’s Facebook data. These are gotten through the sign-in dialogue in which a user gives permission for the app to get one. These tokens are provided once a user logins and gives permission and expire when that user logouts.
  • App Tokens: These are necessary in order to access and modify any of the app settings. These tokens are provided to usually a single person (app administrator) via a secret between the app and Facebook and must be used any time there is a server-to-server call to access settings.
  • Page Access Tokens: This is a token that allows access to a Facebook page of a user. The way to obtain these is to first get a user token and the request permission for the page access token. These are especially valuable for e-commerce apps that want to learn more about their users.

Facebook SDK’s for IOS will manage user access tokens automatically through FBSDKAccessToken. More information is available through the Facebook tutorial on Facebook Login for iOS.

Issues with Tokens

Mind that there may be issues with tokens, and these are should be resolved by developers who know what they are doing. The most common problems arise in the following circumstances:

  • Facebook sessions do get invalidated, usually because of cached data.
  • Tokens can also expire when users do certain things like reset their passwords

Because these things happen, you should not assume that you will get another valid token, at least not from the Facebook SDK. Sometimes, however, you can get another valid token by providing a prompt for the user to re-authenticate with Facebook.

Users sign in through Facebook and then may sign in through another service using the same email address. Or they may sign in on another device, without tapping the “Login with Facebook.” The client will perhaps have “lost” their sessions.

Wiring the session up again will require some app design tweaks on a developer’s part. You will need to be able to load third-party tokens from the backend. Then re-create the Facebook session and place a request.

Check the authorization token and then save the new one to the backend. This should keep a session going. This activity is not automatic through Facebook SDK – it will have to be added.

So that’s how you integrate Facebook login to your app. And if you need help with adding this integration to your existing app or building a new one from scratch, you can count on Alty’s help. We have the the skills, the tools, the experience, and an attractive price on top of it 🙂

Rate the article
[Average: 0]
Want to Get our Digest to Your Inbox?
Great, You are Now Subscribed!
Design & Dev Trends
8 Best Mobile Navigation Design Examples

While there are certain mobile UI rules to keep in mind, you there’s no single best navigation pattern out there.

Leonid Gorev
Design & Dev Trends
5 Top Free Mobile App Builders Reviewed

Get to know what kinds of apps you can use with drag & drop app builders.

Leonid Gorev
Design & Dev Trends
Pros and Cons of Using Xamarin for Mobile App Development

Learn when your business can benefit from cross platform app development with Xamarin and when to choose native app development instead.

Leonid Gorev