- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
1)
最新版本的 Facebook SDK 对 FBFriendPickerViewController 进行了更改。它曾经为您提供一个包含所有 Facebook 好友的好友选择器,但现在它只显示使用过您的应用程序的好友。很方便,但我的应用程序中有需要从用户的整个 friend 中进行选择的功能。
Senario = 我正在尝试使用 friend 选择器来选择一个 friend ,然后在选择之后执行一个 segue,它显示一个 View Controller ,为用户提供他们刚刚选择的那个 friend 的详细信息。这意味着选定的 friend “id”必须保留到下一个 View Controller ,这样我就可以在下一个 VC 上使用“id”检索 friend 信息(由于 friendPicker.selection 属性,这使得 FBFriendPickerViewController 很方便)。
问题 = 有谁知道我可以在好友选择器中获取用户整个 Facebook 好友列表的方法吗?
2)
替代方案 = 另一种可能的解决方案是通过创建表格 View 并使用来自 Facebook 的 JSON 加载表格。从那里我可以将 friend 数据加载到 cellForRowAtIndexPath 中,一切正常。
NSString *accessToken = [FBSession activeSession].accessTokenData.accessToken;
NSString *surl = @"https://graph.facebook.com/me/friends?access_token=%@&fields=picture,name,id";
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:surl, accessToken]];
NSURLRequest * request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *r, NSData *d, NSError *e) {
if (e==nil) {
NSDictionary *jsonData = [NSJSONSerialization JSONObjectWithData:d options:NSJSONReadingAllowFragments error:nil];
friends = [NSMutableArray arrayWithArray:jsonData[@"data"]];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
idx = indexPath.row;
NSSortDescriptor *sort=[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];
[friends sortUsingDescriptors:[NSArray arrayWithObject:sort]];
f = friends[idx];
// Configure the cell...
//cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background_lightgrey.png"]];
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"facebook_blue.png"]];
cell.layer.borderColor = [[UIColor blackColor] CGColor];
//cell.layer.borderWidth = 1;
cell.layer.cornerRadius = 10;
cell.imageView.layer.borderColor = [[UIColor whiteColor] CGColor];
cell.imageView.layer.borderWidth = 1;
cell.imageView.image = [UIImage imageNamed:@"fbDefaultPic.png"];
cell.textLabel.text = f[@"name"];
UIImage *theImage = f[@"image"];
if (theImage==nil) {
cell.imageView.layer.borderColor = [[UIColor whiteColor] CGColor];
cell.imageView.layer.borderWidth = 1;
NSString *url = f[@"picture"][@"data"][@"url"];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
imgData = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
UIImage *img = [UIImage imageWithData:imgData];
dispatch_async(dispatch_get_main_queue(), ^{
cell.imageView.image = img;
//NSMutableDictionary *newFriend = [NSMutableDictionary dictionaryWithDictionary:f];
//friends [idx] = newFriend;
//newFriend [@"image"] = img;
});
});
}
else {
cell.imageView.image = theImage;
}
return cell;
}
替代问题 = 我发现使用这种方式保存所选 friend 的“id”非常困难。 (如果 tableView 有像 FBFriendPickerViewController 这样的 .selection 属性,那将会非常有帮助,但它没有……)。
问题(替代)=任何人都可以帮助我创建 Facebook friend 的 tableView 并能够提取“id”,以便我可以将它存储在一个单例变量中并在我的另一个 View 中使用它 Controller ?
-总结-
问题 1) = 并非所有 friend 都出现,但可以获得 friend 的“id”。
问题 2) = 所有 friend 都出现了,但无法获得 friend 的“id”。
最佳答案
Facebook 平台更新日志
API 的最新版本是 2.2 版,于 2014 年 10 月 30 日推出。
friend 列表现在只返回也使用您的应用的 friend :通过/me/friends 端点返回的 friend 列表现在仅限于已授权您的应用程序的 friend 列表。
关于ios - 如何让 FBFriendPickerViewController 显示所有 friend ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23636409/
我是一名优秀的程序员,十分优秀!