FBFriendPickerViewController is loading a empty tableview intermittently

陌路散爱 提交于 2019-12-11 01:56:49

问题


I am using FBFriendPickerViewController to load friends after user signs in. However, an empty table view is being loaded. The friends of the user from fb are not showing up. Heres the code.

- (IBAction)inviteButtonTouchHandler:(id)sender {
        if (!_friendPickerController) {
            _friendPickerController = [[FBFriendPickerViewController alloc] initWithNibName:nil bundle:nil];
            _friendPickerController.delegate = self;
            _friendPickerController.title = @"Select friends";
            _friendPickerController.allowsMultipleSelection = NO;
        }
        [_friendPickerController clearSelection];
        [_friendPickerController loadData];
        [self presentViewController:_friendPickerController animated:YES completion:nil];
  }  

This code is called after login which is done like this in appDelegate following the Facebook Tutorial -

- (void)openSession
{
    NSArray *permissions = @[@"friends_about_me"];
    [FBSession openActiveSessionWithReadPermissions:permissions
                                       allowLoginUI:YES
                                  completionHandler:
     ^(FBSession *session,
       FBSessionState state, NSError *error) {
         [self sessionStateChanged:session state:state error:error];
     }];
}

回答1:


You need to add the following code in viewDidLoad method of your viewController.

if (!FBSession.activeSession.isOpen) {
    // if the session is closed, then we open it here, and establish a handler for state changes
    [FBSession.activeSession openWithCompletionHandler:^(FBSession *session,
                                                         FBSessionState state,
                                                         NSError *error) {
        switch (state) {
            case FBSessionStateClosedLoginFailed:
            {
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                    message:error.localizedDescription
                                                                   delegate:nil
                                                          cancelButtonTitle:@"OK"
                                                          otherButtonTitles:nil];
                [alertView show];
            }
                break;
            default:
                break;
        }
    }];
}


来源:https://stackoverflow.com/questions/14757817/fbfriendpickerviewcontroller-is-loading-a-empty-tableview-intermittently

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!