Skip to content

Swift Developer Blog

Learn Swift and App Development for iOS

  • Swift Blog
    • UITableView
    • UIImageView
    • UIScrollView
    • UIWebView
    • SubView
    • UIImagePickerController
    • UIPageViewController
    • UITabBarController
    • UIAlertController
    • UISegmentedControl
    • Xcode
    • Firebase
  • Video Tutorials
  • Code Examples
    • Code examples
    • Cheat Sheets
  • Resources
    • Swift Developer
  • Full stack
    • Developer Resources
    • Android & Kotlin
    • Java
    • RESTful Web Services
    • Amazon Web Services
    • Firebase with Kotlin
    • Firebase with Swift
    • Hibernate
    • Git
    • Design Patterns
  • About
  • Contact me
  • Home
  • Facebook SDK and Swift
  • Facebook SDK for iOS – Login & Logout example with Swift
July 27, 2015 by Sergey Kargopolov 5 comments on "Facebook SDK for iOS – Login & Logout example with Swift"

Facebook SDK for iOS – Login & Logout example with Swift

In this video I am going to share with you how to integrate Facebook SDK for iOS into your Swift mobile application and how to implement Facebook login and logout feature.

Integrate Facebook SDK for iOS into Swift Mobile Application

Implement Facebook login and logout button

If you are interested to learn how to implement user sign up, sign in, password reset, email verification and other features with Swift, PHP & MySQL, check out my video course “Swift, PHP & MySQL. Implementing user sign up, sign in, password reset, email verification feature and more”.

I have a similar video course on how to implement above mentioned features with Swift and Parse: “Swift Programming: User sign up, Sign in, Password reset and more”.

Happy coding!


The three AppDelegate functions you need to update to make Facebook login button work:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

 // Override point for customization after application launch.
FBSDKLoginButton.classForCoder()

 return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) 

} 

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {

 return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) 
} 

func applicationDidBecomeActive(application: UIApplication) { 
interface.FBSDKAppEvents.activateApp() 
}

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}
 
func applicationDidBecomeActive(application: UIApplication) {

FBSDKAppEvents.activateApp()

}

Login button code:

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!)
{
if(error != nil)
{
   println(error.localizedDescription)
   return
}

if let userToken = result.token
{
//Get user access token
let token:FBSDKAccessToken = result.tokenprintln("Token = \(FBSDKAccessToken.currentAccessToken().tokenString)") 
 
println("User ID = \(FBSDKAccessToken.currentAccessToken().userID)") 

let protectedPage = self.storyboard?.instantiateViewControllerWithIdentifier("ProtectedPageViewController") as! ProtectedPageViewController

let protectedPageNav = UINavigationController(rootViewController: protectedPage)

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate

appDelegate.window?.rootViewController = protectedPageNav

}

}

 

Posted in: Facebook SDK and Swift
Tagged: Facebook SDK, Facebook Sign in, Sign in

Post navigation

Previous Previous post: UITabBarController example in Swift
Next Next post: Parse Login with Facebook account. Example in Swift.

Primary Sidebar

Find videos

Unit Testing Swift?

Unit Testing Swift Mobile App

Recent Posts

  • Inject JavaScript into WKWebView
  • WKWebView. Load HTML File from App Bundle.
  • UIImagePickerController in Swift with Firebase. Cheat Sheet.
  • Firebase Realtime Database Cheat Sheet
  • Push Notifications with Firebase Cloud Messaging – Cheat Sheet

Search by Tag

AWS Facebook Facebook SDK Facebook Sign in Firebase HTTP HTTP Get HTTP Post Icon Java Keychain Load Images Login MMDrawerController MySQL Navigation Drawer NSURLSession Parse Password PHP Push Notifications Search Sign in SubView Swift UIActivityIndicator UIAlertController UIImage UIImagePickerController UIImageView UIPageViewController UIScrollView UISearchBar UISegmentedControl UITabBarController UITableView UITableViewCell UITableViewController UITableViewDatasource UIWebView Upload Xcode Xcode Tips Xcode Tips and Tricks XIB

Featured posts

  • Left side menu (Navigation Drawer) example with Swift
  • Creating custom user interface files with XIB in Xcode 6 and Swift
  • Add Subview and Remove subview example in Swift
  • Customize UINavigationBar appearance in Swift
  • MBProgressHUD example in Swift
  • iOS Keychain example in Swift
  • Image Upload with Progress Bar example in Swift
  • Circular Image or Image with Rounded Corners. Example in Swift

Copyright © 2023 Swift Developer Blog. Powered by WordPress and Themelia.

Would you like more video tutorials weekly?
  • Swift programming with Parse. Practical Examples.
  • Swift programming with PHP and MySQL. Practical examples.
  • iOS Mobile Apps Development with Swift

Enter your email and stay on top of things,

Subscribe!