Facebook iOS SDK 3.0 - 在FBFriendPickerViewController中保存并重新加载.selection [英] Facebook iOS SDK 3.0 - save and reload .selection in FBFriendPickerViewController

查看:75
本文介绍了Facebook iOS SDK 3.0 - 在FBFriendPickerViewController中保存并重新加载.selection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FBFriendPickerViewController看起来很简单。但是,它可能不是为我想要的场景设计的。



本质上,我想保存用户选择到磁盘的朋友列表。在随后的应用程序启动时,我想显示FBFriendPickerViewController与这些保存的朋友已被选中。



由于.selection属性是只读的,我不知道如何可以加载一个新的FBFriendPickerViewController实例,其中已经有已选择的一部分朋友。

解决方案

最后我找到了解决方案。



有一个NSDictionary dict 其关键是Facebook用户标识,值为该名称。
大致来说,这是代码:

  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]; //这不是必须的
如果(用户){
NSLog(@添加用户:%@,user.name);
[results addObject:user];
}
}
//最后设置选择属性
friendPickerController.selection = results;

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



更新2:如果您填写了 FBGraphUser.h 头文件


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".

解决方案

Finally I've found out the solution.

I have an NSDictionary dict whose key is the facebook user id and the value is the name. Roughly, this is the code:

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;

UPDATE: it seems like it doesn't work properly....you will see the friends correctly checked, but when you will go to parse the .selection when you finish the selection, you will get only the friends you checked in the UI, not the preloaded ones...

UPDATE 2: it seems to work fine if you fill up all the fields listed in the FBGraphUser.h header file

这篇关于Facebook iOS SDK 3.0 - 在FBFriendPickerViewController中保存并重新加载.selection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆