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 Objective-C project. For adding Facebook Login to a Swift project, see Facebook Login in Swift - Getting Started.

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

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

4a. Info.plist

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

4b. Build Settings

  1. Go to the Project Navigator in Xcode and select your project to see project settings.
  2. Select Other Linker Flags for editing.
  3. Add the flag -ObjC to Other Linker Flags for all build targets.

5. Connect Your App Delegate

Add the following to your AppDelegate class. This initializes the SDK when your app launches, and lets the SDK handle results from the native Facebook app when you perform a Login or Share action.
//  AppDelegate.m
#import <FBSDKCoreKit/FBSDKCoreKit.h>

- (BOOL)application:(UIApplication *)application 
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [[FBSDKApplicationDelegate sharedInstance] application:application
  // Add any custom logic here.
  return YES;

- (BOOL)application:(UIApplication *)application 
            openURL:(NSURL *)url 
            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {

  BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
  // Add any custom logic here.
  return handled;
Note that application:openURL:options: is only available in iOS 9 and above. If you are building with an older version of the iOS SDK, you can use:
- (BOOL)application:(UIApplication *)application 
            openURL:(NSURL *)url 
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {

  BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
  // Add any custom logic here.
  return handled;

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.
// 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 eliminates an unnecessary app switch to Facebook if someone already granted permissions to your app:
- (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.
// 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.