Short answer

For a custom Facebook Login button in Swift today, add the SDK with Swift Package Manager from github.com/meta/facebook-ios-sdk (CocoaPods support ended with version 19.0.1), put your app ID, client token and display name in Info.plist, forward URLs through ApplicationDelegate, and call LoginManager().logIn(viewController:configuration:completion:) from your own button. The 2018 code used logIn(readPermissions:) and FBSDKAccessToken, which no longer exist. One new case to handle: the SDK can return Limited Login, with an authentication token but no access token, so a Graph API call isn't always possible.

SWIFT TIPS · LOGIN · FACEBOOK SDK

First posted on April 12, 2018, as "Custom button Sign in Facebook swift 4". Rewritten on November 19, 2026. The SDK details come from the source code, README and changelog in Meta's GitHub repository, read on November 19, 2026; Meta's developer site didn't load for me that day. The Swift code below was type-checked with Swift 6.2.3 (Xcode 26.2, Swift 5 mode) against stand-in types that copy the SDK's signatures. The SDK itself wasn't installed, and no real Facebook login was made.

In 2018 I wanted Facebook Login with my own button instead of the blue one the SDK draws. The post installed the FacebookCore and FacebookLogin pods, added the Facebook keys to Info.plist, made a view controller with a xib, put a button in it, and called LoginManager().logIn(readPermissions: [.publicProfile], viewController: self). After login it requested me from the Graph API with the fields id, name, picture and email, and printed the result.

The idea still works: your own button calling the login manager. Almost every name in that code has changed since. This rewrite gives the current setup, code that matches the current SDK, and the cases the old code didn't handle.

What changed since 2018

  • Installation. The README says CocoaPods is no longer supported starting with v19.0.1, because the CocoaPods Specs repo is becoming read-only; v19.0.0 is the last version published there. Use Swift Package Manager with https://github.com/meta/facebook-ios-sdk. The changelog for 19.0.1 says the repository moved there from the old facebook organization, and old URLs redirect.
  • Minimum iOS version. The 19.0.0 changelog raises the minimum deployment target to iOS 15.0.
  • Names. FBSDKAccessToken.current() is now AccessToken.current, FBSDKGraphRequest is GraphRequest, and the readPermissions login call is gone. The login call takes a LoginConfiguration.
  • Limited Login. The configuration has a tracking setting. Reading LoginManager.swift, a login with tracking: .enabled can switch to the Limited Login flow when advertiser tracking isn't enabled on the device, and Limited Login can finish with an AuthenticationToken and no AccessToken.

Step 1: add the SDK

  1. In Xcode, choose File, Add Package Dependencies.
  2. Enter https://github.com/meta/facebook-ios-sdk and choose "Up to Next Major Version".
  3. Add the FacebookLogin and FacebookCore libraries to your app target. The login code imports the first, the app delegate the second.

If your project still has the old pods, the README's migration steps are: remove the Facebook pods from the Podfile, run pod install (or pod deintegrate if they were your only pods), and add the matching packages. Your import lines don't need to change.

Step 2: Info.plist

Register your app in Meta's developer dashboard to get an app ID and a client token. Then add this to Info.plist, opened as source code, inside the top <dict>:

<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>fbYOUR_APP_ID</string>
    </array>
  </dict>
</array>
<key>FacebookAppID</key>
<string>YOUR_APP_ID</string>
<key>FacebookClientToken</key>
<string>YOUR_CLIENT_TOKEN</string>
<key>FacebookDisplayName</key>
<string>YOUR_APP_NAME</string>

The URL scheme is fb followed by the app ID with no space; the 2018 post wrote it as fb(YourAppID), and the parentheses aren't part of it. The SDK's Settings.swift reads FacebookAppID, FacebookClientToken and FacebookDisplayName from the plist. Its comment describes the client token as needed for certain anonymous API calls, ones made without a user's access token. Meta's setup guide also lists URL schemes for LSApplicationQueriesSchemes, so the Facebook app can be opened for login; I couldn't load that page to check the current list, so copy it from the guide.

Step 3: forward URLs in the app delegate

When login finishes in the Facebook app or the browser, iOS opens your app with a URL. The SDK has to see it:

import UIKit
import FacebookCore

@main
final 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, options: options)
    }
}

If your app uses scenes, the URL arrives in the scene delegate's scene(_:openURLContexts:) instead, and you pass it to the SDK from there.

Step 4: your own button

The 2018 post made a view controller with a xib and dragged a plain button into it, then connected an action. That part doesn't change. The button style is yours, but keep the words "Continue with Facebook" or similar so people know what it does. This is the code behind it:

import UIKit
import FacebookLogin

final class FacebookLoginViewController: UIViewController {
    @IBOutlet private weak var nameLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        if AccessToken.current != nil || AuthenticationToken.current != nil {
            showProfile()   // already logged in from an earlier launch
        }
    }

    @IBAction private func loginTapped(_ sender: UIButton) {
        guard let configuration = LoginConfiguration(permissions: [.publicProfile, .email], tracking: .enabled) else { return }
        LoginManager().logIn(viewController: self, configuration: configuration) { [weak self] result in
            switch result {
            case .success(granted: _, declined: let declined, token: _):
                if declined.contains(.email) {
                    print("Email was declined; the app must work without it.")
                }
                self?.showProfile()
            case .cancelled:
                print("User cancelled login.")
            case .failed(let error):
                print("Login failed:", error.localizedDescription)
            }
        }
    }

    @IBAction private func logoutTapped(_ sender: UIButton) {
        LoginManager().logOut()   // clears AccessToken, AuthenticationToken and Profile
        nameLabel.text = nil
    }

    private func showProfile() {
        // A Graph API call needs an access token. Limited Login gives an
        // authentication token without one, so fall back to Profile.current.
        guard AccessToken.current != nil else {
            nameLabel.text = Profile.current?.name
            return
        }
        GraphRequest(graphPath: "me", parameters: ["fields": "id,name,email"]).start { [weak self] _, result, error in
            if let error = error {
                print("Graph request failed:", error.localizedDescription)
                return
            }
            let fields = result as? [String: Any]
            self?.nameLabel.text = fields?["name"] as? String
        }
    }
}
  • Ask for what you use. .publicProfile and .email are enough for a sign-in. The person can decline email, and the result's declined set says so; the app has to work without it.
  • Three results. The LoginResult enum has .success(granted:declined:token:), .cancelled and .failed, which is close to the 2018 switch. The 2018 code bound three values it never used, which is where its warnings came from.
  • Two kinds of token. If there's an AccessToken, the Graph API works and the code requests id,name,email. If login ended in Limited Login, there's only an AuthenticationToken, so the code shows Profile.current?.name instead. The SDK's Profile has an isLimited flag for this case.
  • No force cast. The 2018 code did result as! [String: AnyObject], which crashes if the response isn't a dictionary. A conditional cast fails quietly.
  • Log out with the SDK. LoginManager().logOut() clears the access token, the authentication token and the profile, according to its doc comment.

Before you ship

  • Offer Sign in with Apple too. Apple's App Review Guidelines, rule 4.8, ask apps that use a third-party login such as Facebook Login for the primary account to also offer an equivalent login that limits data collection to name and email, lets people keep their email private, and doesn't collect app interactions for advertising without consent. Sign in with Apple has those features. The post linked below about an app rejected for Facebook login covers this.
  • Verify on your server. A token on the device proves nothing to your backend by itself. Send it to your server and check it there before you create a session.
  • Privacy details. The README notes that data the SDK collects may need to be declared in App Store Connect's privacy questions.

A quick check for your project

  1. Search for FBSDK and readPermissions. Any match means the code is older than the current SDK.
  2. Check that the URL scheme in Info.plist is fb plus your app ID, with no brackets.
  3. Test login with a test user while the app's tracking permission is denied, and confirm the screen still shows a name.

What the 2018 version said

The post started with a screenshot of Meta's Facebook Login guide, which I left out because it's a third-party page; the current repository is linked below. It then showed the new-file dialog and the xib with the button and code:

Xcode's new file dialog: a Cocoa Touch class named ViewController, a subclass of UIViewController, with Also create XIB file checked

A xib with one blue Login Facebook button, next to the 2018 FacebookLoginViewController code with a warning on the success case

The yellow warning in the second screenshot is the unused grantedPermissions, declinedPermissions and accessToken values.

Sources