Skip to main content

Overview

The Facebook Login SDK exposes two representations of a login outcome:
  • LoginResult — a @frozen Swift enum used by the LoginResultBlock closure. This is the type you receive in the Swift logIn(viewController:configuration:completion:) callback.
  • LoginManagerLoginResult — an NSObject subclass used for Objective-C compatibility and for the LoginManagerLoginResultBlock callback.
Module: FacebookLogin
Declared in: LoginResult.swift, LoginManagerLoginResult.swift

LoginResult enum

@frozen
public enum LoginResult {
    case success(granted: Set<Permission>, declined: Set<Permission>, token: AccessToken?)
    case cancelled
    case failed(Error)
}

Cases

.success(granted:declined:token:)
case
The login completed successfully. Contains the set of granted permissions, the set of declined permissions, and an optional AccessToken. The token is nil when using .limited tracking.
.cancelled
case
The user dismissed the login dialog without completing the flow.
.failed(Error)
case
The login attempt encountered an error. The associated value is the underlying Error.

Pattern matching

loginManager.logIn(viewController: self, configuration: config) { result in
    switch result {
    case let .success(granted, declined, token):
        if granted.contains(.email) {
            print("Email permission granted")
        }
        if let token = token {
            print("Access token:", token.tokenString)
        }
    case .cancelled:
        print("User cancelled login")
    case let .failed(error):
        print("Login error:", error.localizedDescription)
    }
}

LoginResultBlock type alias

public typealias LoginResultBlock = (LoginResult) -> Void

LoginManagerLoginResult class

LoginManagerLoginResult is the Objective-C–compatible result type. You receive it in the LoginManagerLoginResultBlock callback used by logIn(permissions:from:handler:) and reauthorizeDataAccess(from:handler:). Objective-C name: FBSDKLoginManagerLoginResult

Initializer

public init(
    token: AccessToken?,
    authenticationToken: AuthenticationToken?,
    isCancelled: Bool,
    grantedPermissions: Set<String>,
    declinedPermissions: Set<String>
)

Properties

token
AccessToken?
The AccessToken granted by the login attempt. This is nil if the login was cancelled, failed, or used .limited tracking.
authenticationToken
AuthenticationToken?
The AuthenticationToken provided when using .limited tracking (OpenID Connect).
isCancelled
Bool
true if the user dismissed the login dialog without completing the flow.
grantedPermissions
Set<String>
The permissions that were granted during this specific login request. Check AccessToken.current?.permissions for the full set of currently-granted permissions.
declinedPermissions
Set<String>
The permissions that were explicitly declined during this login request.

Objective-C usage example

// Swift equivalent of the ObjC LoginManagerLoginResultBlock pattern
loginManager.logIn(
    permissions: ["public_profile"],
    from: self
) { result, error in
    if let error = error {
        print("Error:", error)
        return
    }
    guard let result = result, !result.isCancelled else {
        print("Cancelled")
        return
    }
    print("Granted:", result.grantedPermissions)
    print("Declined:", result.declinedPermissions)
}

Choosing between the two types

ScenarioRecommended type
Swift code using logIn(viewController:configuration:completion:)LoginResult
Objective-C code or legacy Swift using logIn(permissions:from:handler:)LoginManagerLoginResult
Reauthorizing data accessLoginManagerLoginResult via LoginManagerLoginResultBlock

Build docs developers (and LLMs) love