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 } }