AuthenticationToken instance that provides information about the login attempt that can be used to verify the authentication on the client’s servers. Additionally, we will populate a shared Profile instance that will contain basic information including an app-scoped ID for the user, the user’s name, and profile picture.public_profileemailgaming_profilegaming_user_pictureuser_age_rangeuser_birthdayuser_friendsuser_genderuser_hometownuser_linkuser_locationuser_messenger_contactFBSDKLoginTracking enumeration. The possible values are enabled and limited. For Limited Login, use limited.enum LoginTracking {
case enabled
case limited
}
FBSDKLoginConfiguration to modify the default behavior of a login attempt. This configuration be created with default properties, explicit properties (Swift only), or with one of several initializers:init?(
permissions: Set<Permission> = [],
tracking: LoginTracking = .enabled,
nonce: String = UUID().uuidString
)
| Property | Description |
|---|---|
requestedPermissions: Set<Permissions> (Swift) | Requested permissions for the login attempt. Defaults to an empty set. |
requestedPermissions: Set<String> (ObjC) | Requested permissions for the login attempt. Defaults to an empty set. |
tracking: LoginTracking | Login tracking preference. Defaults to .enabled. |
nonce: String | Nonce that the configuration was created with.
A unique nonce will be used if none is provided to the factory method. |
user_likes does not work if the tracking is .limited.let loginManager = LoginManager()
// Ensure the configuration object is valid
guard let configuration = LoginConfiguration(
permissions:["email", "user_friends", "user_birthday", "user_age_range", "user_gender", "user_location", "user_hometown", "user_link"],
tracking: .limited,
nonce: "123"
)
else {
return
}
loginManager.logIn(configuration: configuration) { result in
switch result {
case .cancelled, .failed:
// Handle error
break
case .success:
// getting user ID
let userID = Profile.current?.userID
// getting pre-populated email
let email = Profile.current?.email
// getting pre-populated friends list
let friendIDs = Profile.current?.friendIDs
// getting pre-populated user birthday
let birthday = Profile.current?.birthday
// getting pre-populated age range
let ageRange = Profile.current?.ageRange
// getting user gender
let gender = Profile.current?.gender
// getting user location
let location = Profile.current?.location
// getting user hometown
let hometown = Profile.current?.hometown
// getting user profile URL
let profileURL = Profile.current?.linkURL
// getting id token string
let tokenString = AuthenticationToken.current?.tokenString
}
}
override func viewDidLoad() {
super.viewDidLoad()
setupLoginButton()
}
func setupLoginButton() {
loginButton.delegate = self
loginButton.permissions = ["email"]
loginButton.loginTracking = .limited
loginButton.nonce = "123" as NSString
}
func loginButton(
_ loginButton: FBLoginButton,
didCompleteWith potentialResult: LoginManagerLoginResult?,
error potentialError: Error?
) {
if let error = potentialError {
// Handle Error
}
guard let result = potentialResult else {
// Handle missing result
}
guard !result.isCancelled else {
// Handle cancellation
}
// Handle successful login
let userID = Profile.current?.userID
let email = Profile.current?.email
let tokenString = AuthenticationToken.current?.tokenString
}