1

I am creating a game for iOS 7 and am trying to implement Game Center leaderboards. I got the app to open the leaderboard when I click a certain button, but it says "No Items". I am not sure right now if it is a problem with the submitting scores or retrieving leaderboards. It appears to be a problem with submitting the score because it says the app name on the top of my leaderboard, but I can't find my error. My code to submit score:

-(void)reportScore:(NSInteger ) highScore {
if ([GKLocalPlayer localPlayer].isAuthenticated) {
    GKScore *scoreReporter = [[GKScore alloc]  initWithLeaderboardIdentifier:@"flapjacks1" forPlayer:[GKLocalPlayer localPlayer].playerID];
scoreReporter.value = highScore;
    NSLog(@"Score reporter value: %@", scoreReporter);
[GKScore reportScores:@[scoreReporter] withCompletionHandler:^(NSError *error) {
    if (error != nil) {
        NSLog(@"Error");
     // handle the reporting error
     }

}];
}

}

This is my method for retrieving the leaderboard:

-(void)displayLeaderboard
{
//NSString *_leaderboardIdentifier = @"flapjacks1";
[[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier, NSError *error) {

    if (error != nil) {
        NSLog(@"%@", [error localizedDescription]);
    }
    else{
        //_leaderboardIdentifier = leaderboardIdentifier;
        GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
        if (gameCenterController != nil)
        {
            gameCenterController.gameCenterDelegate = self;
            gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
            //gameCenterController.leaderboardTimeScope = GKLeaderboardTimeScopeToday;
            gameCenterController.leaderboardIdentifier = @"flapjacks1";
            [self presentViewController: gameCenterController animated: YES completion:nil];
        }
    }

}];

}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • are you using sandbox account ? – Shubhank Mar 10 '14 at 15:45
  • I do not think so, do you have any idea of how to integrate that? Thanks, any help is appreciated – user3402391 Mar 10 '14 at 15:48
  • http://stackoverflow.com/questions/5506893/create-a-sandbox-account-on-game-center-on-iphone – Shubhank Mar 10 '14 at 15:49
  • Ok thanks, but it never even brings me to a prompt to log in to gamecenter. Any ideas on that? Thanks – user3402391 Mar 10 '14 at 15:51
  • did it ever showed you login prompt ? are you authenticating the local GKPlayer ? – Shubhank Mar 10 '14 at 15:53
  • No it never showed the login prompt, but the player is Authenticated, we've done a NSLog to check that. – user3402391 Mar 10 '14 at 15:58
  • so if user is authenticated.. why will it show a gamecenter login prompt – Shubhank Mar 10 '14 at 15:59
  • I'm a bit confused by your last comment. We authenticated our local player through code, I can grab that bit for you – user3402391 Mar 10 '14 at 16:04
  • you call authenticate on gamecenter local player -> the OS authenticates user is logged into the game center app and that object is returned. so there wont be a screen where user will be required to authenticate – Shubhank Mar 10 '14 at 16:05
  • Ok, I will look into this more. Thank you for your help. I am not at a place right now where I can edit the code, so it is a bit hard to fix this now. Could you possibly grab a tutorial that would show how to properly authenticate the local player like you were talking about and post it here? Thanks – user3402391 Mar 10 '14 at 16:07
  • just try to use a sandbox account on simulator in gamecenter app and then submit scores, after that try to check leaderboards.. sorry i dont have proper tutorial. i checked many . you can start with the mobiletuts one. – Shubhank Mar 10 '14 at 16:10

0 Answers0