Calm Turtle
Calm Turtle

Reputation: 292

GKLeaderboard posting problems

I am not sure if sandbox is taking too long to update or if my code is funky.

I am simply grabbing the local players last entered score and adding another score to it and trying to post the result.

Here is my code:

- (void) reportScore: (int64_t) score forCategory: (NSString*) category
{
GKScore *scoreReporter = [[[GKScore alloc]initWithCategory:category] autorelease];
scoreReporter.value = score;

[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
    if (error != nil)
    {
        // handle the reporting error
        NSLog(@"Error reporting score");

    }
}];
}

-(void)postScore:(int64_t)score forCategory:(NSString *)category {

GKLeaderboard *query = [[GKLeaderboard alloc]init];
query.category = category;

if (query != nil)

{

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

        if (error != nil){

            // Handle the error.
            NSLog(@"Error loading scores");

        }
        if (scores != nil){

            // Process the score.

            int64_t newScore = query.localPlayerScore.value + score;

            [self reportScore:newScore forCategory:category];


        }



    }];


}

[query release];
}

Thanks for any help.

EDIT: Sandbox leaderboard has the first score, but will not update the subsequent scores.

Upvotes: 2

Views: 505

Answers (2)

Gajendrasinh Chauhan
Gajendrasinh Chauhan

Reputation: 3397

You need to check property of GKleaderBoard class.For Your Info. see below code.

GKLeaderboardViewController *leaderController = [[GKLeaderboardViewController alloc] init];

     if (leaderboardController != NULL)
     {
        leaderController.category = self.currentLeaderBoard;
        leaderController.timeScope = GKLeaderboardTimeScopeWeek;
        leaderController.leaderboardDelegate = self;
        [self presentModalViewController: leaderController animated: YES];
     }

                                AND

you can also check apple docs for both GKLeaderBoard and GKAchievementViewController class below.

for GKLeaderBoard http://developer.apple.com/library/ios/#documentation/GameKit/Reference/GKLeaderboard_Ref/Reference/Reference.html

for GKAchievementViewController http://developer.apple.com/library/ios/#documentation/GameKit/Reference/GKAchievementViewController_Ref/Reference/Reference.html

Upvotes: 0

Srijith Vijayamohan
Srijith Vijayamohan

Reputation: 915

Having the same issue at my end. It will provide the score correctly for the first time in a session. After that, it keep sending back the same score even if we update the score in that session.

Upvotes: 1

Related Questions