Facebook SDK for iOS - Getting Started

Integrate with Facebook for your iOS app. Build engaging social apps, enable easy login and get more installs.

Requirements: OS X, Xcode (Documentation / Download) and iOS 7 or higher.


1. Download SDK

2. Create Facebook App

3. App Settings

4. Add SDK

5. Configure Xcode

6. Connect Application Delegate

7. Add App Events

Next Steps

1. Download the SDK

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

Download iOS SDK

2. Create a Facebook App

If your app is not yet registered with Facebook and has an app ID, you should create it. You can you share an app ID across platforms.

Create a New App

3. Configure Facebook App Settings for iOS

  1. Select Settings in App Dashboard.
  2. Click Add Platform and choose iOS.
  3. Then provide your Bundle Identifier in the Bundle ID field.
  4. Enable Single Sign On.
  5. Click Save Changes

4. Add the SDK to your Xcode Project

To add the SDK in Xcode:

  1. Open ~/Documents/FacebookSDK
  2. Drag the FBSDKCoreKit.framework to Frameworks in Project Navigator. Create a new group Frameworks if it does not exist.
  3. Choose Create groups for any added folders.
  4. 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. Add /Users/{username}/Documents/FacebookSDK to the project's Framework Search Paths in Xcode's Build Settings.

The SDK automatically loads its framework and resource dependencies.

5. Configure Xcode Project

Now configure the .plist for your project:

  1. In Xcode right-click your .plist file and choose "Open As Source Code".
  2. Copy & Paste the XML snippet into the body of your file (<dict>...</dict>).
  3. Replace:
    • fb{your-app-id} with your Facebook App ID and the prefix fb. E.g.: fb123456.
    • {your-app-id} with your Facebook App ID.
    • {your-app-name} with the Display Name you configured in the app dashboard.
<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>fb{your-app-id}</string>
    </array>
  </dict>
</array>
<key>FacebookAppID</key>
<string>{your-app-id}</string>
<key>FacebookDisplayName</key>
<string>{your-app-name}</string>

For iOS 9 only: Whitelist Facebook Apps

Add the following to your app's .plist

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>fbapi</string>
  <string>fb-messenger-api</string>
  <string>fbauth2</string>
  <string>fbshareextension</string>
</array>
In Detail: Preparing Your App for iOS9

6. Connect Application Delegate

To post process the results from Facebook Login or Facebook Dialogs (or any action that requires switching over to the native Facebook app or Safari) you need to connect your AppDelegate to the FBSDKApplicationDelegate. In your AppDelegate.m add:

//  AppDelegate.m
#import <FBSDKCoreKit/FBSDKCoreKit.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [[FBSDKApplicationDelegate sharedInstance] application:application
    didFinishLaunchingWithOptions:launchOptions];
  // 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
    openURL:url
    sourceApplication:sourceApplication
    annotation:annotation
  ];
  // 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.

7. Add App Events

The SDK is installed and set up. The easiest way to test your implementation is to add App Events to your app. App Events help you understand the makeup of people who engage with 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, or any custom events you can define.

Log App Activations

A basic example is to log app activations. To do so add the following code snippet to your AppDelegate.m:

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

Verify Logging

  1. Compile and launch your app.
  2. Go to the Analytics for Apps Dashboard and select your app.
  3. Navigate to Events > Most Recent.

You should start seeing events show up. It may take a moment for events to show, hit refresh and launch your app multiple times to verify your setup was completed correctly.


To learn how to implement App Events and other products to your app, read our guides listed in Next Steps.