views:

91

answers:

1

Hi,

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.

A: 

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

F.Santoni