简体   繁体   English

集成facebook登录并获取用户详细信息以及ios6中的tabbarcontroller

[英]Integrate facebook login and fetch user details along with tabbarcontroller in ios6

I have implemented facebook login in my app. 我在我的应用程序中实现了facebook登录。

1----> I was able to do facebook login but after that logged in user is able to continue with my app ie a tabbarController with three tab items appears and simultaneously I need to fetch facebook user details (email,firstname,lastname etc) 1 ---->我能够登录facebook,但登录后用户可以继续使用我的应用程序,即出现三个标签项的tabbarController,同时我需要获取Facebook用户详细信息(电子邮件,名字,姓氏等) )

But I was unable to retrieve details. 但我无法检索细节。 I do not understand where am I going wrong. 我不明白我哪里错了。

In my ViewController.m: 在我的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 facebook login page I am getting tabbarController and I am unable to retrieve user details. 但这里没有显示Facebook登录页面我得到tabbarController我无法检索用户的详细信息。

How can I show facebook login page first and then tabbarController with user details? 如何首先显示facebook登录页面,然后使用tabbarController显示用户详细信息? After successful login into facebook how can I continue with my app with a tabbarcontroller with first tabitem(corresponding view )selected? 成功登录Facebook后如何继续使用带有第一个tabitem(相应视图)的tabbarcontroller我的应用程序?

Please help me out in sorting this issue...Please 请帮我解决这个问题...请

You will need to set the readPermissions for getting the email for this method, by passing it an NSArray with object "email". 您需要设置readPermissions以获取此方法的电子邮件,方法是将NSArray传递给对象“email”。 The remaining information such as name etc is returned by default. 默认情况下会返回其他信息,如名称等。

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

of the facebook sdk. facebook sdk。 If im not mistaken, unless specified permission is "email" then the email object of the user dictionary is nil . 如果我没有弄错,除非指定的权限是“email”,否则用户词典的电子邮件对象是nil Modify your state changed handler perhaps to request the user details such as email. 修改您的状态更改处理程序可能会请求用户详细信息,如电子邮件。 Inside the sessionStateChanged: handler if session is open u may call a method that simply does this sessionStateChanged: handler中,如果会话打开,你可以调用一个简单的方法

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

             }
         }];
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM