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

0
Shares
Integrate Facebook Sign In Button in Your iOS App within 60 Minutes!
Rate this post

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 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 sign in with the Facebook 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’.

Facebook1

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

Facebook2

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

Facebook3

Now, create an App from the following link.
https://developers.facebook.com/apps/

Click on “+ Add a New App”.

Facebook4

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

Facebook5

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”.

Facebook6

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

Facebook7

Facebook8

Facebook9

Facebook10

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

Facebook11

Facebook12

Facebook13

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.

Facebook14

Facebook15

CocoaLigature0 
@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 {
                    //error
                } 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
loginManager.logOut()

That’s it! This is the easiest way you can integrate Facebook sign in 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 iPhone 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 project is in good hands!

You can download the source code of Facebook sign In button demo from Github.

 
0
Shares
 

Check How Much Does Facebook Integration Button Cost. Contact Us Now.