This guide shows you how to integrate your iOS app with Facebook using the Facebook SDK for iOS.
Beginning with SDK v13.0 a Client Token is required for all calls to the Graph API.
The Facebook SDK enables:
You will need:
If You Want To | Add This Package to your project |
---|---|
Allow your app to use the Facebook services |
|
Allow users to log into your app and for your app to ask for permissions to access data |
|
Allow your app to share content on Facebook |
|
Allow users to log into your app to enable engagement and promote social features |
|
Info.plist
file with an XML snippet that contains data about your app. After you integrate Facebook Login, certain App Events are automatically logged and collected for Events Manager, unless you disable Automatic App Event Logging. In particular, when launching an app in Korea, please note that Automatic App Event Logging can be disabled. For details about what information is collected and how to disable automatic app event logging, see Automatic App Event Logging.
Info.plist
, and choose Open As ▸ Source Code. <dict>...</dict>
). <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: You may directly set the automatic collection of App Events to “true” or “false” by adding 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 FacebookCore @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 FacebookCore ... 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] ) }
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 API