1. 先 Download Facebook SDK ~ Facebook developer page
  2. 把 FacebookSDK.framework 加入 project 中
  3. 重點來了, 因為 SDK 是 Objective-C 所以得使用 Bridge 的方式才能 import

    • 新增一個 Objective-C header file 內容只要這個就可以了
        #import <FacebookSDK/FacebookSDK.h>
      
    • 到 Build Settings 裡面找到 Swift Compiler - Code Generation ,設定 Objective-C Bridging Headeryour_projectname/Bridge-Header.h 記得不要設定到 for Project 的那格 可參考圖片
    • 確定 Install Objective-C Compatibility Header 為 Yes
    • Done
  4. 在 AppDelegate.swift 中 加入 ...

    func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
        // Override point for customization after application launch.
        FBLoginView.self
        FBProfilePictureView.self
        return true
    }
    
    func application(application: UIApplication, openURL url: NSURL, sourceApplication: NSString?, annotation: AnyObject) -&gt; Bool {
    var wasHandled:Bool = FBAppCall.handleOpenURL(url, sourceApplication: sourceApplication)
    return wasHandled
    }
    
  5. 在 ViewController.swift 加上一些東西

    class ViewController: UIViewController, FBLoginViewDelegate {
        @IBOutlet
        var fbLoginView : FBLoginView!
        override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    
        self.fbLoginView.delegate = self
        //grant permission from facebook
        //self.fbLoginView.readPermissions = []
    }
    
    //MARK: Facebook Delegate Methods
    func loginViewShowingLoggedInUser(loginView: FBLoginView!) {
        println("User Logged In");
    }
    
    func loginViewFetchedUserInfo(loginView : FBLoginView!, user: FBGraphUser) {
        println("User: \(user)")
        println("User ID: \(user.objectID)")
        println("User Name: \(user.name)")
        var userEmail = user.objectForKey("email") as String
        println("User Email: \(userEmail)")
    }
    
    func loginViewShowingLoggedOutUser(loginView : FBLoginView!) {
        println("User Logged Out")
    }
    
    func loginView(loginView : FBLoginView!, handleError:NSError) {
        println("Error: \(handleError.localizedDescription)")
    }
    
  6. 在 StoryBoard 中加入 UIView 並把 Class 設成 FBLoginView

  7. 將 UIView(FBLoginView) 綁定到 ViewController中的 fbLoginView

  8. Follow Facebook 的步驟的話我們得去 plist 裡加點字段

  9. Done ~ 執行 就會看到!!