2
votes

I want a list of all friends of the local player who also play my game.

I thought about doing a query for every friend score on every leaderboard, and finding distinct players:

GKLeaderboard *allScoresEver = [[GKLeaderboard alloc] init];
allScoresEver.playerScope = GKLeaderboardPlayerScopeFriendsOnly;
allScoresEver.range = NSMakeRange(1,100);
allScoresEver.category = nil;

[allScoresEver loadScoresWithCompletionHandler:^(NSArray *scores, NSError *error) {

        // filter out distinct players, favouring scores from our leaderboard
        ...
    }];

...but that seems to only return the last reported score of the local player, instead of every score from every leaderboard, filtered by friends. The docs say setting category to nil should return "all scores previously reported by the game". I guess that means the running instance of the game, not game in the sense of a world-wide app?

Any ideas of an effective way to get the results I want?

1
@SumitMundra thanks, but that's all friends ever. I only want ones that also own the game ("have ever recorded a leaderboard score for this game" is an acceptable substitute).tenpn

1 Answers

0
votes

Trying out similar code I get more than just the local player's results when the category is set to nil, but I only seem to get results for the default leaderboard. This makes some sense I suppose since asking for all results for all leaderboards could end up with a lot of data, but it isn't what the documentation would lead you to believe. Personally, to solve a similar problem I'm just interrogating one of the leaderboards for which every player who has played at least once should have an entry rather than every leaderboard. Seems odd that there isn't a nicer way to get this information since Game Center itself is aware of who has downloaded the app.

Edit: it seems that range = NSMakeRange(1, 100); is a hard limit and considering you can have up to 500 friends, it means this still isn't a useful test to get all friends who also play the game. You can however create a leaderboard with a list of playerIDs, so:

GKLeaderboard *query = [[GKLeaderboard alloc] initWithPlayerIDs:[GKLocalPlayer localPlayer].friends];

would be one way to handle it. I've tested this with a dummy array of 500 player IDs plus my friends list at the end and it worked, but I'd feel better if it could be tested with 500 actual friends - I just don't have the time to make them all!