Cha*_* SP 7 iphone objective-c game-center
我正在使用以下功能向游戏中心提交分数.如何修改下面的代码,以便我只能在已经提交的分数最高的情况下发送分数?而且我不想在当地保持分数.有帮助吗?
- (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];
}];
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
编辑:我刚刚发现它仅由游戏中心处理...只有最高分才会显示在游戏中心应用上.
您可以使用以下方法检索之前的分数
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.
}];
}
Run Code Online (Sandbox Code Playgroud)