How to Customize the Login button in Facebook? I don't want to use Facebook default login button.
For SDK 4.0 :
U should add a button and in button action use the below code :
- (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 : To receive Users 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");
}
}
You should add a UIButton
and add a click method like this:
- (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];
}];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With