
Facebook’s CORRECTED OAuth Documentation
Facebook’s current documentation is out of date…
The Problem: If you follow the steps according to the documentation exactly, your application may work in your simulator, but it may not work on your real device (I’m using an iPhone 11, so I don’t know for sure about other models).
The Solution: Check step 6 if all you want is the solution.
Using:
- XCode 11.2.1
- iOS 13.3.1
- Cocoapods (FBSDKLoginKit)
- Swift 5
1. Create a new Single View Application
Basic stuff first.

Name it something.

Save it wherever you want.
Go to your terminal and navigate to your project’s folder. Run pod init
and pod install
to get your project set up with cocoapods.

Now open your project workspace file with XCode.

Find your Podfile and add your dependencies: FBSDKLoginKit
& FBSDKLoginCore

Go back to your terminal and run another pod install
to get your dependencies into your project.

2. Create a button that will start the login flow.
Go to your root view controller and add a new custom button.


Make sure you can see it logging your print statement when you press it.
2. Create an app in Facebook’s dashboard.
Go to the following url to build your app with Facebook:
https://developers.facebook.com/docs/facebook-login/ios
I’ll go through each step with you…
- Either create a new app or choose an existing one. I’m going to create a new one. Click “Create a New App” , once you’re done it should look like this.

2. Change package manager to Cocoapods

3. For step 3, we’re going to need our bundle identifier so that when we finish the oauth flow, the facebook app knows which application to redirect back to.
You can find your bundle identifier here.

Paste that into step 3 and hit save.

Also, enable single sign-on for your app.

4. Add config to your info.plist
file.

Basically, you just need to copy both of these code chunks and put them into your info.plist
, here’s what it should look like in the end…

5. Connect your app delegate (This is where they screwed up)
They give you 2 code blocks in this step, we’ll only need the Swift code.

To make this super clear, I’ll copy the code into an editor to point out the mistake.

Ignore the error, this is just a demonstration of the code that they give you.
They give you 2 functions in your AppDelegate class.
The function that I’ve highlighted contains some setup that you’ll need in your application. Just grab the highlighted section and paste that into your real AppDelegate
.


FBSDKCoreKit statement)
Now go back to the injectable code that they give you. You see the second function there? You don’t actually need it. Here’s what you actually need to do…
Copy this function:
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else {
return
}
let _ = ApplicationDelegate.shared.application(
UIApplication.shared,
open: url,
sourceApplication: nil,
annotation: [UIApplication.OpenURLOptionsKey.annotation])
}
You need to add this function to your SceneDelegate
file. So let’s do that.


6. Make our Facebook button actually work.
Go back to your ViewController
and add a callback to the facebook button.

All we’re doing here is…
- Checking to see if our AccessToken class (provided by FBSDKLoginKit) has an access token (meaning we’ve logged in before).
- If we have one, then we log out (remove the access token from the app).
- If we don’t have one, we take our user through the login flow, and handle a callback when that login flow has finished.
Now everything should be working properly! 🎉
If you learned something today, cheers to you :)
Happy Coding 📈