iOS Game Center Sandbox: Leaderboards show “No sco

2019-04-10 12:51发布

问题:

So I am sending scores to the GC leaderboards, I receive no errors and the scores apprently send but I still see no scores listed in the leaderboards! The leaderboard itself is listed in Game Center there are just no scores.

According to a Google search and a question on here this could be resolved by attempting to log scores with more than one account. I have tried on three different accounts now both in Simulator (iOS5) and on my iPhone; none of them show any errors when submitting the scores.

The code that sends the score is here:

- (void)reportScore:(NSString *)identifier score:(int)rawScore {

    GKScore *score = [[[GKScore alloc] initWithCategory:identifier] autorelease];
    score.value = rawScore;
    [scoresToReport addObject:score];
    [self save]; // Save here even though we save again in didEnterBackground, just in case of crash...

    if (!gameCenterAvailable || !userAuthenticated) return;
    [self sendScore:score];
}

- (void)sendScore:(GKScore *)score {
    [score reportScoreWithCompletionHandler:^(NSError *error) {
        dispatch_async(dispatch_get_main_queue(), ^(void)
                       {
                           if (error == NULL) {
                               NSLog(@"Successfully sent score!");
                               [scoresToReport removeObject:score];                
                           } else {
                               NSLog(@"Score failed to send... will try again later.  Reason: %@", error.localizedDescription);                
                           }
                       });
    }];
}

回答1:

It suddenly started working (without any code change or even a recompile). I figure it takes a while for the leaderboards to actually appear, for me about 18 hours.

Scores submitted within this time will still record, they just wont be visible instantly.



回答2:

I never got scores to add to the sandbox either, but here is the code I implemented, and it works fine with the version currently in the app store:

GKScore * score = [[[GKScore alloc] initWithCategory:@"com.example.appname.scoreboardname"] autorelease];
score.value = [[NSUserDefaults standardUserDefaults] integerForKey:@"NEWSCORE"];
[score reportScoreWithCompletionHandler:^(NSError *error) {
    dispatch_async(dispatch_get_main_queue(), ^(void) {
        if (error == NULL) {
            NSLog(@"Score Sent");
        } else {
            NSLog(@"Score Failed");
        }
    });
}];

just make sure your GKScore.value is of type int64_t