How to make FBFriendPickerViewController show ALL friends

1)

The FBFriendPickerViewController has changed the latest version of the Facebook SDK. It used to give you a Friend Picker with all your Facebook friends, but now it only shows friends who have used your application. Handy, but I have functionality in my application that should choose from all the user's friends.

Senario = I try to use a friends picker to select a friend, and then after segue is executed, it displays a view controller that gives the details of the friend of the friend they just selected. This means that the selected friends "id" must be stored on the next view controller so that I can get information about friends using "id" on the next VC (which makes FBFriendPickerViewController convenient because of the friendPicker.selection property).

Question = Does anyone know how I can get a list of users of all Facebook friends in my friend picker?

2)

Alternative = Another possible solution could be this way by creating a table view and uploading the table using JSON from Facebook. From there, I can load my friend's data into cellForRowAtIndexPath and that everything works fine.

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 .selection, FBFriendPickerViewController, ...).

( ) = - , tableView Facebook "id" , ?

- -

1) = , "id" .

2) = , "id" .

+4
1

Facebook

API - 2.2, ​​30 2014 .

, : , /me/friends, , .

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

+1

Source: https://habr.com/ru/post/1540396/


All Articles