Swift Facebook Log-in Integration for iPhone App Development

Learn how to integrate Facebook Log-in using Swift from iPhone app development company.

This post has all the steps that iPhone app development company professionals follow to integrate Facebook log-in using Swift. You can read this post and discover what steps are involved and how the team of experts do it.

One liner: In this tutorial we will learn how to integrate Facebook Log-in using Swift.

Features: You can log-in directly in application and fetch user details.

Starts with create one single view application with product name “SwiftFacebookIntegration”. In language field select Swift and in device field select iPhone.

Before we start coding, we require to create and register Application in Facebook.

Now, to create application in Facebook follows below steps:

  1. Go to https://developers.facebook.com and login with your developer account or sign for one.
  2. Click on “My Apps” and select “Add a New App”.
  3. Enter your app name, Contact email and category of your app.
  4. Go to dashboard screen and select setting -> Add Platform ->
  5. Copy Bundle ID from Xcode project and paste in Bundle Id field.
  6. Click to enable to “Single Sign On”.
  7. Click “Save Changes”.

Download Facebook iOS SDK from here. After download add FBSDKLoginKit.framework and FBSDKCoreKit.framework in your project.

In info.plist file we have to set returning URL or redirect URL and add Facebook ID. Make required changes as shown in below screen shot.

Open AppDelegate.swift and import FBSDKCoreKit and FBSDKLoginKit frameworks. For configuring Facebook Login with application implement code in didFinishLaunchingWithOptions() like below screenshot. Next add method openURL() for managing flow once user login and return back to application. For more info please check below screenshot.

Open Main.storyboard and add one UIImageView in main view for display user profile picture. Ctrl drag from image to class and set outlet “facebookImage”. Add one UIView like button size and set class FBSDKLoginButton in identity inspector. Ctrl drag from button to class and outlet “btnFacebook”. Add two UILabel with outlet “facebookName” and “facebookEmail” respectively. Please check below screenshots for more info.

Open ViewController.swift file and import FBSDKCoreKit and FBSDKLoginKit frameworks. Next set delegate “FBSDKLoginButtonDelegate”. In viewDidLoad() method add read permissions and delegate. Check below screenshot for more info.

Next two methods are delegate methods of FBSDKLoginButtonDelegate. In the first method if user login successfully we can fetch user info like name, email and profile picture. Second method is for logout. Please check below screen shot.

Now build and run project. If everything is correct, your app should run properly with below output.

iPhone app development company experts have shared their experience of swift facebook login integration. If there is anything unclear to you, let them know via your comments.

2695 Total Views 1 Views Today