Creating your own custom "Sign In With Facebook" button
Sometimes we want to design our own UI for "Sign In With Facebook" button instead of the original button that comes with FacebookSDK.
- In your storyboard, drag your UIButton and set it however you want it to be.
- Ctrl + drag your button to your view controller as IBAction.
- Inside the IBAction method you will have simulate a tap on the actual Facebook button as follow:
Step 1: Install the SDK
You can install the SDK manually or via
CocoaPods. The latter option is highly recommended.
Put these lines in
pod install in the terminal and open
.xcworkspace instead of
FBSDKShareKit are optional. You may or may not need them.
Step 2: Create an app on Facebook
Go to Quick Starts - Facebook for Developers to create an app.
Facebook will ask you to download the SDK after creating the app. You can skip this part if you installed the SDK via CocoaPods already.
Step 3: Edit
a. To make your app able to "communicate" with Facebook, you need to put some settings in your
.plist file. Facebook will give you the customized snippet on the Quick Starts page.
b. Edit your
.plist file as source code.
c. Paste your customized snippet in the source code. Be careful! The snippet must be exactly the child of the
<dict> tag. Your source code should be something like:
If you paste the snippet at a wrong place, you will run into problems.
Step 4: Tell Facebook your bundle identifier on the Quick Starts page.
=> How to get bundle identifier
Step 5: Edit your
Fetching the facebook user data
After the user signed in to Facebook at your app, now it's time to fetch the data you requested at the
This modified text is an extract of the original Stack Overflow Documentation created by following contributors
and released under CC BY-SA 3.0