Facebook Login for iOS - Quickstart

When people log into your app with Facebook, they can grant permissions to your app so you can retrieve information or perform actions on Facebook on their behalf.

The following steps are for adding Facebook Login to your iOS project.

1. Login

Please log in to Facebook to create apps or register as a developer.

2. Set up Your Development Environment

Use the latest Facebook SDK for iOS to keep your app compatible with the current iOS version.

If you link to the SDKs with CocoaPods, you must update your pods for the SDKs your app uses and recompile your app. You can also download the latest version of the Facebook iOS SDK, integrate it into your app, and recompile.

Set up your development environment before using Facebook Login for iOS.

Using Swift Package Manager (SPM)
Only available for Xcode 11.2 and above.
  1. In Xcode, click File > Swift Packages > Add Package Dependency.
  2. In the dialog that appears, enter the repository URL: https://github.com/facebook/facebook-ios-sdk.
  3. In Version, select Up to Next Major and take the default option.
  4. Complete the prompts to select the libraries you'd like to use in your project.
  5. To use the Objective-C interface exclusively, import the 'FBSDK'-prefixed module.
    Example: import FBSDKCoreKit
    To use the enhanced Swift interface in your code, import the 'Facebook'-prefixed module.
    Example: import FacebookCore

Using Cocoapods

To always link to the most recent version, link to the Facebook iOS SDK with CocoaPods rather than downloading the SDK itself.
  1. Navigate to *.xcworkspace in your project folder in a terminal window.
  2. Make sure you have the CocoaPods gem installed on your machine before installing the Facebook Login pod.
        $ sudo gem install cocoapods
        $ pod init
    This will create a file named Podfile in your project's root directory.
  3. Add the following to your Podfile:
        pod 'FBSDKLoginKit'
  4. Run the following command in your project root directory from a terminal window:
        $ pod install
Your Cartfile should look something like:

github "facebook/facebook-ios-sdk"

Using the Facebook SDK

Download the Facebook SDK for iOS

Download the SDK and unzip the archive to ~/Documents/FacebookSDK.

Add Login Kit to your Xcode Project

  1. Open your application's Xcode project.
  2. If you don't have a Frameworks group in your project, create one by right-clicking on your project in Xcode's Project Navigator and selecting New Group.
  3. Open the unzipped SDK folder (~/Documents/FacebookSDK).
  4. Drag the Bolts, FBSDKCoreKit and FBSDKLoginKit framework files to your project's Frameworks group.
  5. In the dialog that appears, keep the Copy items if needed option selected, and click Finish.

When you use the Facebook SDK, some events in your app are automatically logged and collected for Facebook Analytics unless you disable automatic event logging. For details about what information is collected and how to disable automatic event logging, see Automatic App Event Logging.

3. Register and Configure Your App with Facebook

Register and configure your app so you can use Facebook Login.

3a. Add your Bundle Identifier

You need to login to complete this step.

3b. Enable Single Sign-On for Your App

You need to login to complete this step.

4. Configure Your Project

Configure the information property list file (info.plist) with an XML snippet that contains data about your app.
  1. Right-click info.plist, and choose Open As Source Code.
  2. Copy and paste the following XML snippet into the body of your file ( <dict>...</dict>).
  3. In <array><string> in the key [CFBundleURLSchemes], replace [APP_ID] with your App ID.
  4. In <string> in the key FacebookAppID, replace [APP_ID] with your App ID.
  5. In <string> in the key FacebookDisplayName, replace [APP_NAME] with the name of your app.
  6. To use any of the Facebook dialogs (e.g., Login, Share, App Invites, etc.) that can perform an app switch to Facebook apps, your application's info.plist also needs to include: <dict>...</dict>).

5. Connect Your App Delegate

Replace the code in AppDelegate.swift with the following code. This code initializes the SDK when your app launches, and allows the SDK handle results from the native Facebook app when you perform a Login or Share action:
//  AppDelegate.swift

import UIKit
import FBSDKCoreKit

class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
            didFinishLaunchingWithOptions: launchOptions

        return true
    func application(
        _ app: UIApplication,
        open url: URL,
        options: [UIApplication.OpenURLOptionsKey : Any] = [:]
    ) -> Bool {

            open: url,
            sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
            annotation: options[UIApplication.OpenURLOptionsKey.annotation]



If you are using iOS 13 or above please add the following method to your SceneDelegate:
//  SceneDelegate.swift

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    guard let url = URLContexts.first?.url else {

        open: url,
        sourceApplication: nil,
        annotation: [UIApplication.OpenURLOptionsKey.annotation]

6. Add Facebook Login to Your Code

Use the Facebook Login button in your iOS app.

6a. Add Facebook Login to Your Code

To add a Facebook-branded Login button to your app, add the following code snippet to a view controller.
// Swift
// Add this to the header of your file, e.g. in ViewController.swift 

import FBSDKLoginKit

// Add this to the body
class ViewController: UIViewController {

    override func viewDidLoad() {
        let loginButton = FBLoginButton()
        loginButton.center = view.center
// Objective-C
// Add this to the header of your file, e.g. in ViewController.m 
// after #import "ViewController.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>

// Add this to the body
@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
  // Optional: Place the button in the center of your view.
  loginButton.center = self.view.center;
  [self.view addSubview:loginButton];

At this point you should be able to run your app and log in using the Facebook Login button.

6b. Check Current Login Status

Your app can only have one person logged in at a time. We represent each person logged into your app with the [FBSDKAccessToken currentAccessToken].
The FBSDKLoginManager sets this token for you and when it sets currentAccessToken it also automatically writes it to a keychain cache.
The FBSDKAccessToken contains userID which you can use to identify the user.
You should update your view controller to check for an existing token at load. This avoids unnecessary showing the login flow again if someone already granted permissions to your app:
// Swift

override func viewDidLoad() {

    if let token = AccessToken.current,
        !token.isExpired {
        // User is logged in, do work such as go to next view controller.
// Objective-C
- (void)viewDidLoad
  [super viewDidLoad];
  if ([FBSDKAccessToken currentAccessToken]) {
   // User is logged in, do work such as go to next view controller. 

6c. Ask for Permissions

When using Facebook Login, your app can ask for permissions on a subset of a person's data.
Read Permissions for Facebook Login Button
To request additional read permissions, set the readPermissions property on the FBSDKLoginButton object.
// Swift
// Extend the code sample from 6a. Add Facebook Login to Your Code
// Add to your viewDidLoad method:
loginButton.permissions = ["public_profile", "email"]
// Objective-C
// Extend the code sample from 6a. Add Facebook Login to Your Code
// Add to your viewDidLoad method:
loginButton.readPermissions = @[@"public_profile", @"email"];
The user will be prompted to grant your app with the requested permissions. Note that some permissions will require a Login Review. See Managing Permissions for more information on permissions.

7. Next Steps

Congrats, you've added Facebook Login to your iOS app! Be sure to check out our other documentation pages for more advanced guides.
Implement a data deletion callback to respond the people's request to delete their data from Facebook.
Add events to your app to view analytics, measure ad performance and build audiences for ad targeting.
Check out our advanced setup for Facebook Login for iOS apps.
Manage what data your app has access to through Facebook Login.
Check out how to responds to errors returned by the Facebook SDK.
Test and verify that your Facebook Login flow works.
Depending on the Facebook data you request from people using Facebook Login, you may need to submit your app for review prior to launch.