开发者

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜