加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 17:21:58 所属栏目:百科 来源:网络整理
导读:我在我的应用程序中实现了facebook登录. 1 —-我能够登录facebook登录,但登录后用户可以继续使用我的应用程序,即出现三个标签项的tabbarController,同时我需要获取facebook用户详细信息(电子邮件,名字,姓氏等) 但我无法检索细节.我不明白我哪里错了. 在我的V
我在我的应用程序中实现了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我的应用程序?

请帮我解决这个问题…请

解决方法

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

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

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

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

             }
         }];
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读