Last active
April 7, 2016 06:16
-
-
Save iaserrat/4765b0f3532dfe87986e to your computer and use it in GitHub Desktop.
This is a swift port of the official FacebookSDK login tutorial. It's been tested on Xcode 6 Beta 1 with the iOS 8 Simulator. You can find the official FB tutorial here: https://developers.facebook.com/docs/facebook-login/ios/v2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// YourProject-Bridging-Header.h | |
#import <FacebookSDK/FacebookSDK.h> | |
// AppDelegate.swift | |
import UIKit | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
. | |
. | |
. | |
func application(application: UIApplication, openURL url: NSURL, sourceApplication: NSString?, annotation: AnyObject) -> Bool { | |
var wasHandled:Bool = FBAppCall.handleOpenURL(url, sourceApplication: sourceApplication) | |
return wasHandled | |
} | |
} | |
// ViewController.swift | |
import Foundation | |
import UIKit | |
class LoginViewController: UIViewController, FBLoginViewDelegate { | |
var fbl: FBLoginView = FBLoginView() | |
@IBOutlet var loginView : FBLoginView | |
@IBOutlet var profilePictureView : FBProfilePictureView | |
@IBOutlet var userNameTxt : UILabel | |
@IBOutlet var logStatusTxt : UILabel | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
fbl.delegate = self | |
loginView.readPermissions = ["public_profile", "email", "user_friends"] | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
func loginViewShowingLoggedInUser(loginView: FBLoginView) { | |
logStatusTxt.text = "You are logged in!" | |
} | |
func loginViewFetchedUserInfo(loginView: FBLoginView?, user: FBGraphUser) { | |
profilePictureView.profileID = user.objectID | |
userNameTxt.text = user.first_name + " " + user.last_name | |
} | |
func loginViewShowingLoggedOutUser(loginView: FBLoginView?) { | |
profilePictureView.profileID = nil | |
userNameTxt.text = "" | |
logStatusTxt.text = "You are logged out!" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It works on beta 4!