//Add the normal button then add your own image and tittle and give the action the button and use the below code in the button action.
NSMutableDictionary *fbResultData;
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login
logInWithReadPermissions: @[@"public_profile", @"email", @"user_friends"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(@"Process error");
} else if (result.isCancelled) {
NSLog(@"Cancelled");
} else {
NSLog(@"Logged in");
if ([FBSDKAccessToken currentAccessToken])
{
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me?fields=id,name,age_range,birthday,devices,email,gender,last_name,family,friends,location,picture" parameters:nil]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSString * accessToken = [[FBSDKAccessToken currentAccessToken] tokenString];
NSLog(@"fetched user:%@ ,%@", result,accessToken);
fbResultData =[[NSMutableDictionary alloc]init];
if ([result objectForKey:@"email"]) {
[fbResultData setObject:[result objectForKey:@"email"] forKey:@"email"];
}
if ([result objectForKey:@"gender"]) {
[fbResultData setObject:[result objectForKey:@"gender"] forKey:@"gender"];
}
if ([result objectForKey:@"name"]) {
NSArray *arrName;
arrName=[[result objectForKey:@"name"] componentsSeparatedByString:@" "];
[fbResultData setObject:[arrName objectAtIndex:0] forKey:@"name"];
}
if ([result objectForKey:@"last_name"]) {
[fbResultData setObject:[result objectForKey:@"last_name"] forKey:@"last_name"];
}
if ([result objectForKey:@"id"]) {
[fbResultData setObject:[result objectForKey:@"id"] forKey:@"id"];
}
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:[NSString stringWithFormat:@"me/picture?type=large&redirect=false"]
parameters:nil
HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
if (!error){
if ([[result objectForKey:@"data"] objectForKey:@"url"]) {
[fbResultData setObject:[[result objectForKey:@"data"] objectForKey:@"url"] forKey:@"picture"];
}
//You get all detail here in fbResultData
NSLog(@"Final data of FB login********%@",fbResultData);
self.fullNameTextField.text = [fbResultData objectForKey:@"name"];
self.lastNameTextField.text = [fbResultData objectForKey:@"last_name"];
[_customFaceBookButton setImage:[UIImage imageNamed:@"fb_connected"] forState:UIControlStateNormal];
} }];
}
else {
NSLog(@"result: %@",[error description]);
AlertView *alert = [[AlertView alloc] initWithTitle:NSLocalizedString(@"Error", nil) message:[error description] delegate:nil cancelButtonTitle:NSLocalizedString(@"DISMISS", nil) otherButtonTitle:nil];
[alert showInView:self.view.window];
}
}];
}
else{
[[FBSDKLoginManager new] logOut];
[_customFaceBookButton setImage:[UIImage imageNamed:@"fb_connected"] forState:UIControlStateNormal];
}
}
}];