The Reusable Facebook Login Components for iOS is the easiest way to get user data from Facebook .
- Get Default data of user from facebook
- Get Specific data of user from facebook
- iOS 8.0+
- Xcode 7.3+
To incorporate the SSFacebookLogin library into your Xcode project utilizing CocoaPods, please reference it within your Podfile as shown below:
pod 'SSFacebookLogin'To add SSFacebookLogin as a dependency to your project, follow these steps:
- Open your Swift project in Xcode.
- Navigate to
File->Add Package Dependencies.... - Paste
https://github.com/SimformSolutionsPvtLtd/SSFacebookLogin.gitinto the search bar. - Choose the version you want to use and click
Add Package.
If you prefer not to use any of the dependency managers above, you can integrate SSFacebookLogin into your project manually.
- Just copy
LoginManager.swift,FaceBookConstant.swiftanduserData.swiftfrom theClassesfolder into your Xcode project. - Make sure to add Facebook SDK or Pod's for iOS.
- For minimum
iOS 11.0use6.0.4 - For minimum
iOS 12.0or above use7.0.0 - For minimum
iOS 13.0or above use7.2.0
- Right-click
Info.plist, and choose Open As ▸ Source Code. - Copy and paste the following XML snippet into the body of your file (
<dict>...</dict>)<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string>fbAPP-ID</string> </array> </dict> </array> <key>FacebookAppID</key> <string>APP-ID</string> <key>FacebookClientToken</key> <string>CLIENT-TOKEN</string> <key>FacebookDisplayName</key> <string>APP-NAME</string>
- In
CFBundleURLSchemes, replace APP-ID with your App ID. - In
FacebookAppID, replace APP-ID with your App ID. - In
FacebookClientToken, replace CLIENT-TOKEN with the value found under Settings > Advanced > Client Token in your Facebook App Dashboard. - In
FacebookDisplayName, replace APP-NAME with the name of your app.
- Add following code blocks in
AppDelegate.swiftfile- In didFinishLaunchingWithOptions method,
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Add below line for facebook configuration LoginManager.shared.facebookConfiguration(application, didFinishLaunchingWithOptions: launchOptions) return true }
- In openUrlWithOption method,
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { return LoginManager.shared.faceboolUrlConfigurationWithOptions(app, open: url, options: options) }
- Voila 🪄✨💫 !
- For more details => Facebook Integration for iOS
Example 1 (Get default data of user when no any arguments passed - use this for version 7.1.0 or below)
LoginManager.shared.loginWithFacebook(controller: self, { (token, error) in
if error == nil {
print(token?.userID ?? "",token?.tokenString ?? "")
}
}) { (result, error) in
if error == nil {
if let userData = result as? UserData {
print(userData)
print(userData.id)
} else {
print(result ?? "")
}
}
} LoginManager.shared.loginWithFacebook(permission: [.email, .publicProfile, .userBirthday],
requriedFields: [.birthday, .about, .email], controller: self, { (token, error) in
if error == nil {
print(token?.userID ?? "",token?.tokenString ?? "")
}
}) { (result, error) in
if error == nil {
if let uResult = result {
print(uResult)
}
}
}Example 3 (Get specific data of user by passing argument and passing token to Firebase for using Firebase - use this for version 7.2.0)
LoginManager.shared.logInWithFacebookFirebase(permission: [.email, .publicProfile, .userBirthday],
requriedFields: [.birthday, .about, .email], tracking: [.limited || .enabled], controller: self, { (token, nonce, error) in
if error == nil {
print(token?.userID ?? "",token?.tokenString ?? "")
}
}) { (userData, error) in
if error == nil {
if let uResult = result {
print(uResult)
}
}
}Example 4 (Get specific data of user by passing argument with limted login option - use this for version 7.2.0)
LoginManager.shared.login(permission: [.email, .publicProfile, .userBirthday],
requriedFields: [.birthday, .about, .email], tracking: [.limited || .enabled],controller: self, { (token, error) in
if error == nil {
print("token \(token)")
}
}) { (userData, error) in
if error == nil {
if let uResult = result {
print(uResult)
}
}
}Whether you're helping us fix bugs, improve the docs, or a feature request, we'd love to have you! 💪
Check out our Contributing Guide for ideas on contributing.
Give a ⭐️ if this project helped you!
This project is licensed under the MIT License - see the LICENSE file for details