项目作者: fahidattique55

项目描述 :
Facebook manager for social media login integration.
高级语言: Swift
项目地址: git://github.com/fahidattique55/NBFacebookManager.git
创建时间: 2017-06-14T05:59:03Z
项目社区:https://github.com/fahidattique55/NBFacebookManager

开源协议:MIT License

下载


Swift version
Support Dependecy Manager
Version
License
Platform

Features

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

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

  1. $ gem install cocoapods

To integrate NBFacebookManager into your Xcode project using CocoaPods, specify it in your Podfile:

  1. source 'https://github.com/CocoaPods/Specs.git'
  2. platform :ios, '9.0'
  3. use_frameworks!
  4. target '<Your Target Name>' do
  5. pod 'NBFacebookManager'
  6. end

Then, run the following command:

  1. $ pod install

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,
  1. func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
  2. FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
  3. return true
  4. }
  5. func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
  6. return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
  7. }
  8. @available(iOS 9.0, *)
  9. func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
  10. return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
  11. }

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
  1. facebookManager.tryAuthenticate(fromViewController: self, success:{ facebookToken in
  2. self.getProfileIfNeeded()
  3. }) { error in
  4. print("Error: \(String(describing: error?.localizedDescription))")
  5. }
  6. private func getProfileIfNeeded(){
  7. facebookManager.fetchLoggedUserInfo(successBlock: { (userInfo) in
  8. print("\(String(describing: userInfo))")
  9. }) { (error) in
  10. print("Error: \(String(describing: error?.localizedDescription))")
  11. }
  12. }
  • 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)