0
votes

My game implements a custom user interface that lists the local player's friends.

I also have a Game Center leaderboard.

When my game lists the players, it also tries to load their scores from the leaderboard, using this code:

    GKLeaderboard *request = [[GKLeaderboard alloc] initWithPlayerIDs:myFriends];
    request.timeScope = GKLeaderboardTimeScopeAllTime;
    request.identifier = @"my_leaderboards";
    if (request != nil) {
        [request loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error) {
            if (error != nil) {
                NSLog(@"Error: %@",error.localizedDescription);
            }
            if (scores != nil) {
                NSLog(@"WORKED: %@",scores);
            }
        }];
    }

And it works just fine.

... except when one of the friends has no score (for instance, they never played the game in the first place). When one of the players in myFriends has no score entry in the leaderboard, the completion handler is never called. There is no error and no score reported, because it never fires in the first place.

I realised this when testing an account that has two friends. One friend has played the game (so they have a score), and the other has not. The completion handler never got called. Then, I unfriended the guy that had no score, and the completion handler worked fine, returning the score of the friend that did have a score.

I somewhat understand this behaviour - after all, I'm asking it to give me a score that does not exist. But is there a workaround? As in, tell it to return a 0 if there is no score?

iOS 7.

1

1 Answers

0
votes

It cannot be helped, the completion handler indeed won't be called because there is no score entry in the leaderboards. Although I still don't understand why doesn't it just return an error saying so.

Since the custom friend list just shows statistics, I just put a loading icon in place for each statistic. If the handler is not called for more than 10 seconds, I assume that there is no score entry and just display a 0.