

| 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 |
Info.plist file with an XML snippet that contains data about your app.
Info.plist, and choose Open As ▸ Source Code.<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>
<array><string> in the key >[CFBundleURLSchemes], replace APP-ID with your App ID.<string> in the key FacebookAppID, replace APP-ID with your App ID.<string> in the key FacebookClientToken, replace CLIENT-TOKEN with the value found under Settings > Advanced > Client Token in your App Dashboard.<string> in the key FacebookDisplayName, replace APP-NAME with the name of your app.Info.plist also needs to include the following:<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-share-api</string>
</array>
FacebookAutoLogAppEventsEnabled as a key in Info.plist.



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]
)
}
}
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]
)
}
// Add this to the header of your file, e.g. in ViewController.swift
import FBSDKLoginKit
// Add this to the body
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let loginButton = FBLoginButton()
loginButton.center = view.center
view.addSubview(loginButton)
}
}
AccessToken.current.
LoginManager sets this token for you and when it sets AccessToken.current it also automatically writes it to the keychain store.
AccessToken contains userID which you can use to identify the user.
override func viewDidLoad() {
super.viewDidLoad()
if let token = AccessToken.current,
!token.isExpired {
// User is logged in, do work such as go to next view controller.
}
}
permissions property on the FBLoginButton object.
// Extend the code sample from 6a. Add Facebook Login to Your Code
// Add to your viewDidLoad method:
loginButton.permissions = ["public_profile", "email"]