4

FBFriendPickerViewController seems pretty straightforward. However, it may not be designed for the scenario I want.

Essentially, I want to save a list of friends the user selects to disk. On subsequent app launches, I want to show the FBFriendPickerViewController with these "saved" friends as being already selected.

Since the .selection attribute is readonly, I'm not sure how I can load a new instance of FBFriendPickerViewController with a subset of friends already "selected".

4

1 回答 1

1

最后我找到了解决方案。

我有一个 NSDictionary dict,其键是 facebook 用户 ID,值是名称。粗略地说,这是代码:

NSMutableArray *results = [[NSMutableArray alloc] init];
for (id key in dict) {
  NSString *name = [dict valueForKey:key];
  id<FBGraphUser> user = (id<FBGraphUser>)[FBGraphObject graphObject];
  user.id = key;
  [user setName:name]; // This is not mandatory
  if (user) {
    NSLog(@"adding user: %@", user.name);
    [results addObject:user];
  }
}
// And finally set the selection property
friendPickerController.selection = results;

更新:似乎它无法正常工作....您会看到正确检查了朋友,但是当.selection您完成选择后去解析时,您只会得到您在 UI 中检查的朋友,而不是预装的...

更新 2:如果您填写FBGraphUser.h头文件中列出的所有字段,它似乎工作正常

于 2014-04-27T17:44:18.810 回答