微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ios – 如何让FBFriendPickerViewController显示所有朋友

1)

FBFriendPickerViewController与最新版本的Facebook SDK发生了变化.它曾经给你一个朋友选择器与你的所有Facebook朋友,但现在它只显示已经使用你的应用程序的朋友.很方便,但我的应用程序中有功能需要从用户整个朋友中进行选择.

Senario =我正在尝试使用朋友选择器来选择朋友,然后在选择之后执行segue,其显示视图控制器,该控制器向用户提供他们刚刚选择的朋友的详细信息.这意味着所选择的朋友“id”必须持久保存到下一个视图控制器,这样我就可以使用下一个VC上的“id”来检索朋友信息(这使得FBFriendPickerViewController因为friendPicker.selection属性而变得很方便).

问题=有没有人知道我可以在朋友选择器中获得整个Facebook好友的用户列表?

2)

替代=另一种可能的解决方案是通过这种方式创建一个表视图并使用Facebook的JSON加载表.从那里我可以将朋友数据加载到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;
}

替代方案的问题=我发现使用这种方式持久保留所选朋友的“id”非常困难. (如果tableView具有像FBFriendPickerViewController这样的.selection属性,但它不会……)会非常有用.

问题(换句)=任何人都可以帮我一个方法,我可以创建Facebook好友的tableView,并能够提取“id”,以便我可以将它存储在一个单一变量中,并在我的其他视图控制器中使用它?

– 总结 –

问题1)=并非所有朋友都出现,但可以得到朋友的“id”.

问题2)=所有朋友出现,但不能得到朋友的“id”.

解决方法

Facebook平台更新日志

最新版本的API是版本2.2,于2014年10月30日推出.

好友列表现在只返回同时使用您的应用的朋友:
通过/ me / friends端点返回的朋友列表现在仅限于已授权您的应用的朋友列表.

https://developers.facebook.com/docs/apps/changelog#v2_1

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐