Question

I am using below function to submit score to game center. How to modify below code so that I can send the score only if it is highest than already submitted score? And I dont want to maintain the scores locally. Any help?

- (void) reportScore: (int64_t) score forCategory: (NSString*) category 
{
 GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:category] autorelease]; 
 scoreReporter.value = score;
 [scoreReporter reportScoreWithCompletionHandler: ^(NSError *error) 
  {
   [self callDelegateOnMainThread: @selector(scoreReported:) withArg: NULL error: error];
  }];
}

Thanks.

Edit : I just found that it is handled by the game center only... Only the top score will displayed on the gamecenter app.

Was it helpful?

Solution

You can retrieve the previous score using

GKLeaderboard *query = [[GKLeaderBoard alloc] initWithPlayerIDs:[NSArray arrayWithObject:yourPlayerId]];

if (query != nil)

{

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

        if (error != nil)

            // handle the error.

        if (scores != nil)

            // process the score information.

        }];

}

Get more information on Apple GameKit Programming Guide

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top