NBFacebookManager 0.0.2

NBFacebookManager 0.0.2

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jun 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Fahid Attique.



 
Depends on:
FBSDKCoreKit>= 0
FBSDKLoginKit>= 0
 

  • By
  • Fahid Attique

Features

  • Integrate facebook login in your application with only two steps.

Pre-Requisite

  • Please visit Facebook Developer Site to create a new application and follow the instructions to get facebook App-ID setup in plist file of your Xcode project.

Usage

Step 1

  • Install the NBFacebookManager pod.
  • Add following code in your Appdelegate.swift file,
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

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


func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {

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

 
@available(iOS 9.0, *)
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {

    return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}

Step 2

  • Create the FacebookManager instance in your controller to authenticate user and get its facebook profile.

fileprivate let facebookManager = FacebookManager()

  • Authenticate the user using ‘facebookManager’ as given below
 
facebookManager.tryAuthenticate(fromViewController: self, success:{ facebookToken in

    self.getProfileIfNeeded()

}) { error in

    print("Error: \(String(describing: error?.localizedDescription))")
}


private func getProfileIfNeeded(){

    facebookManager.fetchLoggedUserInfo(successBlock: { (userInfo) in

        print("\(String(describing: userInfo))")

    }) { (error) in
        print("Error: \(String(describing: error?.localizedDescription))")
    }
}

 
  • Congratulations! You have successfully integrated facebook login in your application.

License

NBFacebookManager is available under the MIT license. See the LICENSE file for more info.

Author

Fahid Attique - (https://github.com/fahidattique55)