Integrate facebook login and get user information with tabbarcontroller in ios6

I have implemented facebook login in my application.

1 ----> I was able to log in to facebook, but after that the logged in user will be able to continue his application, i.e. a tabbarController appears with three tabs, and at the same time I need to get facebook user data (email, firstname, lastname, etc.)

But I could not get the details. I do not understand where I am mistaken.

In my ViewController.m:

- (IBAction)performLogin:(id)sender { AppAppDelegate *appDelegate = (AppAppDelegate *) [[UIApplication sharedApplication] delegate]; [appDelegate openSessionWithAllowLoginUI:YES]; UITabBarController *tabBarController=[[UITabBarController alloc]init]; SearchViewController *searchViewController=[[SearchViewController alloc]initWithNibName:@"SearchViewController" bundle:nil]; UProfile *uprofile=[[UProfile alloc]initWithNibName:@"UProfile" bundle:nil]; userprofile.title=@ "My Profile"; LogOut *logout=[[LogOut alloc]initWithNibName:@"LogOut" bundle:nil]; logout.title=@ "Sign out"; tabBarController.viewControllers=[NSArray arrayWithObjects:searchViewController,uprofile,logout, nil]; [self presentModalViewController:tabBarController animated:YES]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sessionStateChanged:) name:FBSessionStateChangedNotification object:nil]; } - (void)sessionStateChanged:(NSNotification*)notification { if (FBSession.activeSession.isOpen) { [FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id<FBGraphUser> user, NSError *error) { if (!error) { NSString *fbUserEmail= @""; NSLog(@"%@",user); fbUserEmail=[user objectForKey:@"email"]; AppAppDelegate *appDelegate = (AppAppDelegate *) [[UIApplication sharedApplication] delegate]; appDelegate.fbEmail=fbUserEmail; } } ]; } } 

But here, without showing the facebook login page, I get a tabbarController and I cannot get user details.

How can I open facebook login page first and then tabbarController with user details? After successfully logging into facebook, how can I continue to work with my application using the tabbarcontroller with the first tabitem (corresponding view)?

Please help me sort this problem ... Please

+4
source share
1 answer

You will need to set readPermissions to receive email for this method, passing it an NSArray with an "email" object. The remaining information, such as name, etc., is returned by default.

 + (BOOL)openActiveSessionWithReadPermissions:(NSArray*)readPermissions allowLoginUI:(BOOL)allowLoginUI completionHandler:(FBSessionStateHandler)handler; 

on facebook sdk. If im is not mistaken, if the specified permission is not "email", then the email object of the user dictionary is nil . Modify your state change handler, possibly to request user data, such as email. Inside the sessionStateChanged: handler, if the session is open, you can call a method that just does it

 if (FBSession.activeSession.isOpen) { [[FBRequest requestForMe] startWithCompletionHandler: ^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) { if (!error) { NSLog(@"%@", user); NSLog(@"%@", [user objectForKey:@"email"]); } }]; } 
+1
source

All Articles