Skip to content
iOSTutorialJunction
iOSTutorialJunction

Hub of iOS app development tutorials

  • Home
  • Contact Us
  • Privacy Policy
  • Portfolio

Login and get user profile from Facebook in Swift

/ Facebook login, facebook SDK Swift, swift3 / By Aman Aggarwal
Login and get user profile from facebook swift

With the introduction of Swift by Apple, all of sudden every aspect of iOS development changes. Today in every apps, login through social networking is used. Facebook also released their SDK with swift language and in this tutorial we will learn how to login using Facebook swift SDK and get logged in user profile information.

Set up app on Facebook developer and add app ID to your project .plist file

Create a new project (I am considering that you know how to create a project using xcode). Now go to https://developers.facebook.com/

On right side corner, you will find “My Apps“, on its expansion click “Add a new app“. Enter the information as per the fields. Select the platform for your app  as iOS.

Facebook login in swift creating app on facebook developer portal

Skip the first and second step as we are going to use swift SDK and that can only be installed using pods. Enter you bundle id of your project (it should be same as listed in your project, otherwise Facebook login will not work).  Skip 4th step and copy the .plist info shown in 5th step to your project .plist file (if you don’t know how to do it then right click on your project .plist file and open it as source file, after that paste the info as shown in the Facebook developer portal).

Install Facebook SDK using pods

You can install Facebook SDk using cocoa pods by visiting this link https://github.com/facebook/facebook-sdk-swift

For how to install cocoa-pods, you can learn more about  here 

Integration of Facebook login with Swift

At this stage we are done with our Swift3 SDK for Facebook. Open your AppDelegate.swift and import FacebookLogin and FacebookCore frameworks. Made changes to your AppDelegate.swift file as shown below

Open you ViewController.swift file, create an IBAction for Facebook login and named it loginWithFacebook. Below is the code that get authentication token from Facebook. We are showing code for the whole file, and please import frameworks as done in AppDelegate.swift.

If all goes well without any error, you will get authentication token from Facebook. 

You can use below code to get user basic information, like name, email and Facebook ID.

Where to go from here 

In this tutorial, you learned how to login and get profile information from Facebook using Facebook swift3 SDK in iOS.  You can download the source code from Facebook-login-with-swift3. If you have any questions, feel free to comment and I will try to answer those as soon as I can. Stay tuned for more tutorials on swift.

← Previous Post
Next Post →

Connect on topmate

Search

iOS Developer jobs

Follow on Facebook

Archives

Copyright © 2025 iOSTutorialJunction | Powered by Astra WordPress Theme
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Cookie settingsACCEPT
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT