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

时间:2012-12-15 05:05:54

标签: iphone xcode facebook facebook-login

我在我的应用程序中实现了facebook登录。

1 ---->我能够登录facebook登录,但登录后用户可以继续使用我的应用程序,即tabbarController出现三个标签项目,同时我需要获取Facebook用户详细信息(电子邮件,名字,姓氏等)

但我无法检索细节。我不明白我哪里错了。

在我的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;
             }
         }
         ];
    }
}

但是这里没有显示facebook登录页面我得到了tabbarController,我无法检索用户详细信息。

如何首先显示facebook登录页面,然后使用tabbarController显示用户详细信息? 成功登录Facebook后,我如何继续使用带有第一个tabitem(相应视图)的tabbarcontroller我的应用程序?

请帮我解决这个问题......请

1 个答案:

答案 0 :(得分:1)

您需要设置readPermissions以获取此方法的电子邮件,方法是将NSArray传递给对象“email”。默认情况下会返回其他信息,如名称等。

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

如果我没有弄错,除非指定的权限是“email”,否则用户词典的电子邮件对象是nil。修改您的状态更改处理程序可能会请求用户详细信息,如电子邮件。如果会话打开,在sessionStateChanged:处理程序内部你可以调用一个简单地执行此操作的方法

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

             }
         }];
    }
相关问题