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

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

2a. Download the Facebook SDK for iOS

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

2b. 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.
  3. Open ~/Documents/FacebookSDK.
  4. Drag FBSDKCoreKit and FBSDKLoginKit to Frameworks in Project Navigator.
  5. Open Xcode's Build Settings tab in your project.
  6. Add ~/Documents/FacebookSDK to the project's Framework Search Paths.

When you use the Facebook SDK, 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 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. If you 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 .plist also need to handle this.

5. Connect Your App Delegate

To post-process the results from actions that require you to switch to the native Facebook app or Safari, such as Facebook Login or Facebook Dialogs, you need to connect your AppDelegate class to the FBSDKApplicationDelegate object. To accomplish this, add the following code to your AppDelegate.m file.
//  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 
    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];


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 you add Facebook Login, your app can ask someone for permissions on a subset of that person's data.
Read Permissions for Facebook Login Button
For the Facebook-branded login button (FBSDKLoginButton) use the readPermissions property to request additional read permissions.
In your view header file add:
//  ViewController.h
#import <FBSDKLoginKit/FBSDKLoginKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet FBSDKLoginButton *loginButton;
In your view file add:
// Extend the code sample provided in "7. Add Facebook Login Button Code"
// In your viewDidLoad method:
loginButton.readPermissions = 
  @[@"public_profile", @"email", @"user_friends"];
Your app will now ask for the person's email address and friend list.

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