Overview
LoginManager is the primary entry point for Facebook Login in your iOS app. It works directly with AccessToken (for data access) and AuthenticationToken (for authentication), and sets the current tokens upon successful authorizations—or sets them to nil when the user logs out.
Before calling a login method, you should check AccessToken.current to see whether a cached token is already available.
FacebookLoginDeclared in:
LoginManager.swiftObjective-C name:
FBSDKLoginManager
Initializers
init(defaultAudience:)
Creates a new LoginManager instance.
The default audience to use when the user grants publish permissions. See
DefaultAudience for available values.Properties
Controls which audience can see content posted by your app on the user’s behalf. Set this before calling a login method if you need publish permissions. Defaults to
.friends.Methods
logIn(viewController:configuration:completion:)
Logs the user in or requests additional permissions. This is the primary Swift login method.
The view controller from which to present the login UI. If
nil, the topmost view controller is determined automatically.The login configuration describing the permissions and tracking preferences for this login attempt. Must not be
nil.A closure called with a
LoginResult value when the login attempt finishes.completion receives a LoginResult enum value:
logIn(permissions:from:handler:)
Logs the user in using an array of permission strings. This method is available for both Swift and Objective-C callers.
An array of permission name strings to request, e.g.
["public_profile", "email"].The view controller from which to present the login UI. Pass
nil to use the topmost view controller.A callback invoked with a
LoginManagerLoginResult? and an optional Error.logOut()
Logs the user out by setting AccessToken.current, AuthenticationToken.current, and Profile.current to nil.
reauthorizeDataAccess(from:handler:)
Requests the user’s permission to reauthorize your app’s data access after it has expired due to inactivity.
The view controller from which to present the reauthorization UI.
A callback invoked when the reauthorization attempt completes.
AccessToken.isDataAccessExpired returns true. You must have a current AccessToken before calling this method.
DefaultAudience enum
| Case | Description |
|---|---|
.friends | Only the user’s Facebook friends can see posts made by the app (default). |
.onlyMe | Only the user themselves can see posts made by the app. |
.everyone | All Facebook users can see posts made by the app. |
URLOpening conformance
LoginManager conforms to the URLOpening protocol so it can handle redirect URLs from Facebook’s OAuth flow. You typically do not need to call these methods directly; instead, register LoginManager in your app’s UIApplicationDelegate.