We have made a change to endpoints for Limited Login; it is now accessible under limited.facebook.com
When people log into your app with Facebook, they can grant permissions to your app so you can retrieve information or perform actions on Facebook on their behalf.
The following steps are for adding Facebook Login to your iOS project.
Set up your development environment before using Facebook Login for iOS.
Using Swift Package Manager (SPM)
| 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 |
|
Register and configure your app so you can use Facebook Login by adding your Bundle Identifier.
The bundle identifier (Bundle ID) should appear in the box below. If the box is empty, find your bundle identifier in your Xcode Project's iOS Application Target and paste it into the box below.
You can change your bundle identifier via the iOS section on the settings page.
App Settings > Basic > + Platform > iOS
Configure the 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>).
<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>
You may directly set the automatic collection of App Events to “true” or “false” by adding FacebookAutoLogAppEventsEnabled as a key in Info.plist.
Your project will need to include the Keychain Sharing capability in order for login to work in Mac Catalyst applications.



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 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]
)
}
}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 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]
)
}Use the Facebook Login button in your iOS app.
6a. Add Facebook Login to Your Code
To add a Facebook-branded Login button to your app, add the following code snippet to a view controller.
// Add this to the header of your file, e.g. in ViewController.swift
import FacebookLogin
// Add this to the body
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let loginButton = FBLoginButton()
loginButton.center = view.center
view.addSubview(loginButton)
}
}At this point you should be able to run your app and log in using the Facebook Login button.
6b. Check Current Login Status
Your app can only have one person logged in at a time. We represent each person logged into your app with AccessToken.current.
The LoginManager sets this token for you and when it sets AccessToken.current it also automatically writes it to the keychain store.
The AccessToken contains userID which you can use to identify the user.
You should update your view controller to check for an existing token at load. This avoids unnecessary showing the login flow again if someone already granted permissions to your app:
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.
}
}6c. Ask for Permissions
When using Facebook Login, your app can ask for permissions on a subset of a person's data. Facebook Login requires advanced public_profile permission, to be used by external users.
Read Permissions for Facebook Login Button
To request additional read permissions, set the 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"]
The user will be prompted to grant your app with the requested permissions. Note that some permissions will require a Login Review. See Managing Permissions for more information on permissions.
Congrats, you've added Facebook Login to your iOS app! Be sure to check out our other documentation pages for more advanced guides.
Implement a Data Deletion CallbackImplement a data deletion callback to respond the people's request to delete their data from Facebook.
Add App EventsAdd events to your app to view analytics, measure ad performance and build audiences for ad targeting.
Advanced Topics & SetupCheck out our advanced setup for Facebook Login for iOS apps.
PermissionsManage what data your app has access to through Facebook Login.
Handling ErrorsCheck out how to responds to errors returned by the Facebook SDK.
App ReviewDepending on the Facebook data you request from people using Facebook Login, you may need to submit your app for review prior to launch.
Create Your Own Login FlowFor building your own login flow, see Manually Build a Login Flow.