FBLoginButton is a UIButton subclass that automatically manages the login and logout flow. When the user is logged out it shows “Continue with Facebook”; when they are logged in it shows “Log out” and presents a confirmation sheet before clearing the session. You do not need to add any tap targets — the button handles everything internally.
Add the button programmatically
Add the button in Interface Builder
Set the custom class
In the Identity Inspector, set Class to
FBLoginButton and Module to FBSDKLoginKit.Connect the delegate outlet
Control-drag from the button to your view controller and connect it to the
delegate @IBOutlet.Set permissions
Assign permission strings to thepermissions property before the button appears on screen:
Configure login tracking
SetloginTracking to switch between standard and Limited Login:
Configure a nonce
For OIDC replay protection you can supply a custom nonce. The value must be a non-empty string without whitespace; invalid values are silently ignored and a UUID is used instead:Implement LoginButtonDelegate
Conform toLoginButtonDelegate to react to login and logout events:
| Method | When it fires |
|---|---|
loginButtonWillLogin(_:) | Just before the login UI appears. Return false to abort. |
loginButton(_:didCompleteWith:error:) | After the login attempt completes (success, cancel, or error). |
loginButtonDidLogOut(_:) | After the user confirms logout. |
Tooltip behavior
The button can show an onboarding tooltip the first time it appears. You can control this withtooltipBehavior:
Default audience
If you request publish permissions, setdefaultAudience to control the initial sharing scope: