How to change default login button in FBSDKLoginButton in ios?

How to setup Facebook login button? I do not want to use the default login button on Facebook.

+5
source share
4 answers

For SDK 4.0:

U should add a button and in the button action use the code below:

- (IBAction)loginButtonClicked:(id)sender { FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; [login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { if (error) { // Process error NSLog(@"error %@",error); } else if (result.isCancelled) { // Handle cancellations NSLog(@"Cancelled"); } else { if ([result.grantedPermissions containsObject:@"email"]) { // Do work NSLog(@"%@",result); NSLog(@"Correct"); } } }]; } 

Updated:. For user information

  - (IBAction)loginButtonClicked:(id)sender { FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; [login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { if (error) { // Process error NSLog(@"error %@",error); } else if (result.isCancelled) { // Handle cancellations NSLog(@"Cancelled"); } else { if ([result.grantedPermissions containsObject:@"email"]) { // Do work [self fetchUserInfo]; } } }]; } -(void)fetchUserInfo { if ([FBSDKAccessToken currentAccessToken]) { NSLog(@"Token is available"); [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if (!error) { NSLog(@"Fetched User Information:%@", result); } else { NSLog(@"Error %@",error); } }]; } else { NSLog(@"User is not Logged in"); } } 
+14
source

You must add the UIButton and add the click method as follows:

 - (IBAction)fbLogin:(id)sender { [FBSession.activeSession closeAndClearTokenInformation]; [FBSession openActiveSessionWithReadPermissions:@[@"public_profile"] allowLoginUI:YES completionHandler:^(FBSession *fbSession, FBSessionState state, NSError *error) { [self sessionStateChanged:fbSession state:state error:error]; }]; } 
+1
source
 FBLoginView *fbLoginView = [[FBLoginView alloc] initWithPermissions:[NSArray arrayWithObject:@"publish_actions"]]; fbLoginView.frame = CGRectMake(0, 200, 271, 37); for (id obj in fbLoginView.subviews) { if ([obj isKindOfClass:[UIButton class]]) { UIButton * loginButton = obj; UIImage *loginImage = [UIImage imageNamed:@"YourImg.png"]; [loginButton setBackgroundImage:loginImage forState:UIControlStateNormal]; [loginButton setBackgroundImage:nil forState:UIControlStateSelected]; [loginButton setBackgroundImage:nil forState:UIControlStateHighlighted]; [loginButton sizeToFit]; } } 
0
source

I will just end up in iOS 9. Put this code in the button action method.

 [FBSession openActiveSessionWithReadPermissions:@[@"public_profile",@"email",@"user_friends"] allowLoginUI:YES completionHandler: ^(FBSession *session, FBSessionState state, NSError *error) { // The session is open. Get the user information and update the UI. [FBRequestConnection startWithGraphPath:@"me" parameters:@{@"fields": @"first_name,last_name, email"} HTTPMethod:@"GET" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { if (!error) { // Set the use full name. NSLog(@"FBresponse: =>%@",result); } else{ NSLog(@"%@", [error localizedDescription]); } }]; }]; 
0
source

All Articles