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"); } }
source share