How to implement Game Center Leaderboards in iOS 7?

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];
        }
    }

}];

}

So, I'm not sure if I am improperly accessing the leaderboard or if the leaderboard really has no data. I have been searching all over and can't find an answer. Help is greatly appreciated.

Answers


Have you added the leaderboard information to the Application in iTunes Connect and submitted your application so that the Status is Waiting for Binary Upload? You may also need to wait 24 hours after setting the application status, before you can use the Sandbox version of new leaderboards.

You need to make sure you enable the Game Center components (Leaderboards and Achievements) for the version of the application you are submitting, which is separate from the area where you create the leaderboards in iTunes Connect.


Are you sure you are initializing and updating score in the same class? if you initializes in app delegate but uploading score in some other class then it can create the problem, for example look the following:

You authenticated the player in app delegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

if ([GameCenterManager isGameCenterAvailable])

{

    isGameCenterAvailable = YES;
    self.gameCenterManager = [[[GameCenterManager alloc] init] autorelease];
    [self.gameCenterManager setDelegate:self];
    [self.gameCenterManager authenticateLocalUser];
    }
else
    {
    isGameCenterAvailable = NO;
    // The current device does not support Game Center.
    }

then want to upload the score in some other class, use the object of app delegate:

- (void) submitScore2 : (int) curScore
{
    if(curScore > 0)
    {
    [[self delegate].gameCenterManager reportScore: curScore forCategory: self.currentLeaderBoard];
    }
}  

Need Your Help

VBA excel code to insert an entire row below matching a variable number of matching values

excel vba matching

I am a novice at writing vba code and would appreciate some guidance and help writing a basic macro. I am sorting data by three headings, and then separating the data by insering a blank row for ma...