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:

You have two ways to set up your app to use the Facebook SDK. If you haven't registered your application with Facebook, the simplest and quickest option is to use the Quick Start tool. The alternative is to skip the Quick Start and use the manual instructions below.

Quick Start for iOS

Step 1: Configure Facebook App Settings for iOS

  1. Open the Facebook App Dashboard by clicking on the button below and selecting your application.
  2. Select Settings from the left navigation.
  3. Click Add Platform at the bottom of the page and select iOS.
  4. Locate your bundle identifier in Xcode and copy it to your clipboard.
  5. Return to the App Dashboard and paste your bundle identifier into the Bundle ID field.
  6. Enable Single Sign On.
  7. Click Save Changes at the bottom of the App Dashboard window.

Step 2: Download Facebook SDK for iOS

  1. Download the SDK using the button below.
  2. Unzip the archive to ~/Documents/FacebookSDK.

Step 3: Add SDK to Project

To add the SDK in Xcode:

  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 using Finder.
  4. Drag the Bolts.framework, FBSDKCoreKit.framework, FBSDKLoginKit.framework, and FBSDKShareKit.framework files into the Frameworks group of Xcode's Project Navigator. In the displayed dialog, choose Create groups for any added folders and deselect Copy items into destination group's folder. This references the SDK where you installed it rather than copying the SDK into your app.
  5. Open Xcode's Build Settings tab in your project.
  6. Add ~/Documents/FacebookSDK to the project's Framework Search Paths setting.

Step 4: Configure Xcode Project

  1. In Xcode, secondary-click your project's .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>
      <string>{human-readable reason for photo access}</string>
  4. Replace fb{your-app-id} with your Facebook app ID, prefixed with fb. For example, fb123456. You can find your app ID on the Facebook App Dashboard.
  5. Replace {your-app-id} with your app ID.
  6. Replace {your-app-name} with the display name you specified in the App Dashboard.
  7. Replace {human-readable reason for photo access} with the reason your app needs photo access.

Step 5: 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 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 
            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {

  BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
  // 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 6: 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.m
#import <FBSDKCoreKit/FBSDKCoreKit.h>
- (void)applicationDidBecomeActive:(UIApplication *)application {
  [FBSDKAppEvents activateApp];

To verify logging:

  1. Compile and run your app.
  2. Go to the Analytics for Apps Dashboard and select your app.
  3. 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.

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 APILike Button for iOS
Advanced Configuration