-1

我正在创建一个想要列出 facebook 朋友的应用程序。为此,我做了以下事情。

- (void)viewDidLoad
{        
    arrayFriends=[[NSMutableArray alloc]init];
    [super viewDidLoad];
    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;
            }
        }];
    }       
}

-(void)viewWillAppear:(BOOL)animated
{
    if (self.friendPickerController == nil) {
        // Create friend picker, and get data loaded into it.
        self.friendPickerController = [[FBFriendPickerViewController alloc] init];
        self.friendPickerController.title = @"Pick Friends";
        self.friendPickerController.delegate = self;
    }

    [self.friendPickerController loadData];
    [self.friendPickerController clearSelection];
    [self.friendPickerController.view setFrame:CGRectMake(0, 77, 320, 383)];
    [self.view addSubview:self.friendPickerController.view];
    // iOS 5.0+ apps should use [UIViewController presentViewController:animated:completion:]

}
4

2 回答 2

3

带有朋友列表的视图控制器 您可以获得像这张图片一样的朋友列表,您需要在 viewWillAppear:method 中添加以下代码

 if (self.friendPickerController == nil) {
    // Create friend picker, and get data loaded into it.
    self.friendPickerController = [[FBFriendPickerViewController alloc] init];
    self.friendPickerController.title = @"Pick Friends";
    self.friendPickerController.delegate = self;
}

[self.friendPickerController loadData];
[self.friendPickerController clearSelection];

[self presentModalViewController:self.friendPickerController animated:YES];

对于完成和取消按钮操作,我们应该分别调用以下方法,

- (void)facebookViewControllerDoneWasPressed:(id)sender{
  //code goes here
}
- (void)facebookViewControllerCancelWasPressed:(id)sender{
 [self dismissModalViewControllerAnimated:YES];
}
于 2012-10-05T06:28:08.553 回答
-1

您需要考虑的几件事在 iSpark 用作源材料的教程中没有解释(他们的 2013 年评论者之一可能希望他们知道):

  1. 出现在朋友选择器中的用户只是自己安装了应用程序的用户。这是较新的,可能在原始帖子发布时不适用。
  2. 您需要用户的 user_friends 权限才能查看任何朋友。

更多内容:Facebook iOS 选择好友表空白

于 2014-12-14T06:01:23.580 回答