Getting Started with the Facebook SDK for iOS

The Facebook SDK for iOS is the easiest way to integrate your iOS app with Facebook. It enables:

Step 1: Configure Facebook App Settings for iOS

  1. Open the Facebook App Dashboard by clicking the button below.
  2. Open Facebook App Dashboard

  3. Select your app.
  4. In the left navigation pane, select Settings -> Basic.
  5. If the iOS platform isn't currently in your app, click Add Platform at the bottom of the page and select iOS.
  6. Locate your bundle identifier in Xcode and copy it to your clipboard.
  7. Return to the App Dashboard and paste your bundle identifier into the Bundle ID field.
  8. Enable Single Sign On.
  9. Click Save Changes at the bottom of the App Dashboard window.

You can link to the SDK using the following methods:

Using Swift Package Manager (SPM) - Note: Only available for Xcode 11.2 and forward

Using CocoaPods

Using Carthage

Manually Installing Frameworks

Using Swift Package Manager (SPM)

Only available for Xcode 11.2 and forward

  1. In Xcode, click File > Swift Packages > Add Package Dependency.
  2. In the dialog that appears, enter the repository URL:
  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

  1. Navigate to 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 'FBSDKCoreKit'

    If using Facebook Login and Sharing, also add:

    pod 'FBSDKLoginKit'
    pod 'FBSDKShareKit'
  4. Run the following command in your project root directory from a terminal window:
    $ pod install

Using Carthage

We support Carthage.

Your Cartfile should look something like:

github "facebook/facebook-ios-sdk"

Manually Installing Frameworks

Download and unzip the SDK and install the desired frameworks. Just ensure that the -ObjC flag is set.

Step 3: Configure Info.plist

  1. In Xcode, right-click your project's Info.plist file and select Open As -> Source Code.
  2. Insert the following XML snippet into the body of your file just before the final </dict> element.

  3. <key>CFBundleURLTypes</key>
  4. Replace {your-app-id}, and {your-app-name} with your app's App's ID and name found on the Facebook App Dashboard.

Step 4: Connect 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 or AppDelegate.swift file.

//  AppDelegate.swift
import FacebookCore

func application(
    _ application: UIApplication, 
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
    // Override point for customization after application launch.

        didFinishLaunchingWithOptions: launchOptions
    return true

func application(
    _ app: UIApplication, 
    open url: URL, 
    options: [UIApplication.OpenURLOptionsKey : Any] = [:]
) -> Bool {
    return ApplicationDelegate.shared.application(
        open: url,
        options: options
//  AppDelegate.m
#import <FBSDKCoreKit/FBSDKCoreKit.h>

- (BOOL)application:(UIApplication *)application 
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  // You can skip this line if you have the latest version of the SDK installed
  [[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 openURL:url options:options];
  // Add any custom logic here.
  return handled;

Note: In the sample implementation of -application:openURL:sourceApplication:annotation: above, the call to FBSDKApplicationDelegate is required for deferred deep linking to work correctly.

Step 5: Add App Events

Now that the SDK is installed and configured, the easiest way to test it is to add App Events to your app. App Events help you understand how people are using your app. This is done by logging events via one of 14 predefined events such as added to cart in a commerce app or level achieved in a game. You can even define your own custom events.

Log App Activations

To see how many people are using your application, log app activations by adding the following code to your AppDelegate.m file.

// AppDelegate.swift
import FacebookCore

func applicationDidBecomeActive(_ application: UIApplication) {
//  AppDelegate.m
#import <FBSDKCoreKit/FBSDKCoreKit.h>
- (void)applicationDidBecomeActive:(UIApplication *)application {
  [FBSDKAppEvents activateApp];

To verify logging:

  1. Compile and run your app.
  2. Go to the Facebook Analytics Dashboard and select your app.
  3. Open Facebook Analytics

  4. From the menu on the left, select Activity -> Events.

There will be a short delay before your activations show on the event dashboard. If you don't see anything, wait a minute and refresh the page.

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.

Next Steps

To learn how to implement App Events and other Facebook products to your app, click one of the buttons below.

Sharing in iOSAdd Facebook LoginAdd App EventsUse Graph API
Advanced Configuration