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.
Download the SDK and unzip the archive to ~/Documents/FacebookSDK.
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 AppSettings in App Dashboard.Add Platform and choose iOS. Bundle ID field.Single Sign On. Save ChangesTo add the SDK in Xcode:
~/Documents/FacebookSDK FBSDKCoreKit.framework to Frameworks in Project Navigator. Create a new group Frameworks if it does not exist.Create groups for any added folders.Copy items into destination group's folder. This references the SDK where you installed it rather than copying the SDK into your app./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.
Now configure the .plist for your project:
.plist file and choose "Open As Source Code".<dict>...</dict>).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>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
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.
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.
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];
}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.