# Getting Started with the Facebook SDK for iOS
This guide shows you how to integrate your iOS app with Facebook using the Facebook SDK for iOS.
The Facebook SDK enables:
- [Facebook Login](https://developers.facebook.com/documentation/facebook-login/ios) - Authenticate people with their Facebook credentials.
- [Share and Send dialogs](https://developers.facebook.com/documentation/sharing/ios) - Enable sharing content from your app to Facebook.
- [App Events](https://developers.facebook.com/documentation/app-events/getting-started-app-events-ios) - Log events in your application.
- [Graph API](https://developers.facebook.com/docs/graph-api) - Read and write to Graph API.
## Before You Start
You will need:
- A [Meta Developer account](https://developers.facebook.com/documentation/development/register)
- A [Meta App ID](https://developers.facebook.com/documentation/development/create-an-app)
- A [Client Token](https://developers.facebook.com/documentation/development/create-an-app/app-dashboard/advanced-settings#client-token)
- A project with **UIKit App Delegate** selected for **Life Cycle**
## Step 1: Set Up Your Development Environment
- In Xcode, click **File > Swift Packages > Add Package Dependency**.
- In the dialog that appears, enter the repository URL: [https://github.com/facebook/facebook-ios-sdk](https://github.com/facebook/facebook-ios-sdk).
- In **Version**, select **Up to Next Major** and the default option.
- Complete the prompts to select the libraries you want to use in your project.
| If You Want To | Add This Package to your project |
| --- | --- |
| Allow your app to use the Facebook services | `FBSDKCoreKit` |
| Allow users to log into your app and for your app to ask for permissions to access data | `FBSDKLoginKit` |
| Allow your app to share content on Facebook | `FBSDKShareKit` |
| Allow users to log into your app to enable engagement and promote social features | `FBSDKGamingServicesKit` |
## Step 2: Configure Your Project {#configure-your-project}
Configure the `Info.plist` file with an XML snippet that contains data about your app.
- Right-click `Info.plist`, and choose **Open As ▸ Source Code**.
- Copy and paste the following XML snippet into the body of your file ( `<dict>...</dict>`).
```
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fbAPP-ID</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>APP-ID</string>
<key>FacebookClientToken</key>
<string>CLIENT-TOKEN</string>
<key>FacebookDisplayName</key>
<string>APP-NAME</string>
```
- In `<array><string>` in the key `[CFBundleURLSchemes]`, replace *APP-ID* with your App ID.
- In `<string>` in the key `FacebookAppID`, replace *APP-ID* with your App ID.
- In `<string>` in the key `FacebookClientToken`, replace *CLIENT-TOKEN* with the value found under **Settings** > **Advanced** > **Client Token** in your App Dashboard.
- In `<string>` in the key `FacebookDisplayName`, replace *APP-NAME* with the name of your app.
- To 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 `Info.plist` also needs to include the following:
```
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-share-api</string>
</array>
```
Your project will need to include the Keychain Sharing capability in order for login to work in Mac Catalyst applications.
- Select the **+ Capability** button in the **Signing & Capabilities** tab when configuring your app target.
- Find and select the **Keychain Sharing** capability.
- Ensure that the **Keychain Sharing** capability is listed for the target.
## Step 3: Connect the App Delegate
Replace the code in `AppDelegate.swift` method with the following code. This code initializes the SDK when your app launches, and allows the SDK to handle logins and sharing from the native Facebook app when you perform a Login or Share action. Otherwise, the user must be logged into Facebook to use the in-app browser to login.
```
// AppDelegate.swift
import UIKit
import FBSDKCoreKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
ApplicationDelegate.shared.application(
application,
didFinishLaunchingWithOptions: launchOptions
)
return true
}
func application(
_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]
) -> Bool {
ApplicationDelegate.shared.application(
app,
open: url,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplication.OpenURLOptionsKey.annotation]
)
}
}
```
iOS 13 moved opening URL functionality to the `SceneDelegate`. If you are using iOS 13, add the following method to your `SceneDelegate` so that operations like logging in or sharing function as intended:
```
// SceneDelegate.swift
import FBSDKCoreKit
...
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else {
return
}
ApplicationDelegate.shared.application(
UIApplication.shared,
open: url,
sourceApplication: nil,
annotation: [UIApplication.OpenURLOptionsKey.annotation]
)
}
```
## Step 4: Build and Then Run Your Project in the Simulator
In Xcode, select an iOS simulator and click **Run**. Xcode builds your project and then launches the most recent version of your app running in Simulator.
## Step 5: See the Results in Events Manager
The [Events Manager](https://www.facebook.com/events_manager2/) displays the events you send to Facebook. If this is the first time you launched your app with this code, you may have to wait at least 20 minutes before your events appear.
**Note: ** Events may take up to 20 minutes to appear in the dashboard.
## Next Steps
To learn how to implement App Events and other Facebook products to your app, click one of the buttons below.
[Sharing in iOS](https://developers.facebook.com/documentation/sharing/ios)
[Add Facebook Login](https://developers.facebook.com/documentation/facebook-login/ios)
[Add App Events](https://developers.facebook.com/docs/ios/app-events)
[Use Graph API](https://developers.facebook.com/documentation/ios/graph)
[Advanced Configuration](https://developers.facebook.com/documentation/ios/advanced)