Integrate Facebook Sign In Button in Your iOS App within 60 Minutes!

Integration of Facebook sign in button is quite common in mobile apps. It allows app users to register themselves through a single tap on the screen of their smartphones. And the main benefit you get is that your app registration rate boosts.

By adding a Facebook login button, not only it allows to attach social characteristics, but it is used as a login system instead of creating long registration forms.

This Facebook login integration is supported since the launch of iOS 6, even when it is still necessary to add Facebook SDK manually in your app. However, in this iOS app tutorial, we’re going to approach with a relatively easy approach.

With this approach, you’ll learn how to add Facebook sign in button that provides app users a standard Facebook button to log in and log out from the iOS app.

Let’s Get Started!

👉 Create a new project under the file menu and select ‘Single View Application’.


👉 In the next tab, give a name to your project. Here, we’re going to name it as “SOSocialLogin”.


👉 After naming your project, select a dictionary to save your project.


👉 Now, create an App from the following link.

👉 Click on “+ Add a New App”.


👉 Fill the Display Name (app name), Contact Email, and Category and click on “Create App ID”.


👉 Once you create App ID, it’ll navigate you to Facebook app dashboard.

👉 Here, go to Get Started With The Facebook SDK and click on “Choose a Platform”.


👉 Select iOS from the given options and follow the rest of the steps given by Facebook iOS SDK document.





👉 After following all these steps, go to “App Review” section and Make SOSocialLogin public key to YES.




👉 Once finished with this, it’s time to start coding in XCode.

import FBSDKCoreKit in AppDelegate.swift and add the following delegate for invoking proper processing of responses during interaction with native Facebook app or Safari for authorization flow.CocoaLigature1

    func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool
        return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)

Add a button in “ViewController” in “Main.storyboard” and set action of a button.



@IBAction func actionFB(sender: AnyObject) {
import FBSDKLoginKit in “ViewController.swift” and create object of FBSDKLoginManager
    //Create object of FBSDKLoginManager
    let loginManager: FBSDKLoginManager = FBSDKLoginManager()

👉 For Login from Facebook add following code in “actionFB” function

    //Action on facebook button
    @IBAction func actionFB(sender: AnyObject) {
        //Check FB session validation
        if FBSDKAccessToken.currentAccessToken() == nil {
            //Session is not active
            //Go for Facebook login
            //Take default permissions("public_profile","email","user_friends")
            loginManager.logInWithReadPermissions(["public_profile","email","user_friends"], fromViewController: self, handler: { (result:FBSDKLoginManagerLoginResult!, error:NSError!) -> Void in
                if error != nil {
                } else if result.isCancelled {
                    //Login process cancelled by user
                } else {
                    //Successfully loggedIn
        } else {
            //Facebook session is active

👉 If your Facebook session is active then for log out you need to use logout() function of FBSDKLoginManager

//Facebook Logout

That’s it! This is the easiest way you can integrate Facebook login button in your iOS app within just 60 minutes. However, if you face any issue implementing Facebook login button in your iOS app, you can contact us.

Space-O Technologies is an award-winning iOS app development company in India with more than 5 years of experience. Additionally, we’ve already worked with 25+ successful startups throughout our journey and helped them to achieve success with such features. Therefore, you can be the rest assured that your mobile app development project is in good hands!

You can download the source code of Facebook Login button example from Github.

Author Bio
Hitesh Trivedi
Hitesh Trivedi
Designation: iOS Team Lead

Hitesh Trivedi is an iOS Team Lead at Space-O Technologies. He has over 10 years of experience in iOS app development. He has guided to develop over 100 iPhone apps with unique features and functionalities. He has special expertise in Swift and Objective-C.