Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone gamecenter submitting highest score?

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.

like image 849
Chandan Shetty SP Avatar asked Oct 06 '10 12:10

Chandan Shetty SP


1 Answers

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

like image 57
Francescu Avatar answered Oct 19 '22 18:10

Francescu