“GKScore必须指定排行榜。”

在尝试将Game Center集成到iOS 7应用程序时,是否有人遇到此错误?

GKScore必须指定排行榜。

这是失败的代码:

if(points > 0) { //Fails on the next line [self.gameCenterManager reportScore:points forCategory:self.currentLeaderBoard]; } GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init]; if (leaderboardController != NULL) { leaderboardController.category = self.currentLeaderBoard; leaderboardController.timeScope = GKLeaderboardTimeScopeWeek; leaderboardController.leaderboardDelegate = self; [self presentViewController:leaderboardController animated:YES completion:nil]; } 

更新我尝试了另一种方法仍然得到相同的错误。

其他方法:

 GKScore *scoreReporter = [[GKScore alloc] initWithCategory:self.currentLeaderBoard]; scoreReporter.value = points; [scoreReporter reportScoreWithCompletionHandler:^(NSError *error) { if (error != nil) { [self showAlert:@"Game Center Error" theMessage:@"There was a problem uploading your score to Game Center, if this problem persists, please contact JApp Design." alertTag:0]; } }]; 

有任何想法吗?

我和你有同样的问题,但我解决了我的问题..

这是我的原始代码。

 GKScore *scoreReporter = [[GKScore alloc] initWithLeaderboardIdentifier: identifier]; scoreReporter.value = score; scoreReporter.context = 0; scoreReporter.shouldSetDefaultLeaderboard = YES; NSArray *scores = @[scoreReporter]; [GKScore reportScores:scores withCompletionHandler:^(NSError *error) { //Do something interesting here. [self callDelegateOnMainThread: @selector(scoreReported:) withArg: NULL error: error]; }]; 

从这里开始,我删除了该行。 scoreReporter.shouldSetDefaultLeaderboard = YES所以它工作正常。

随着iOS 7.0的推出,这种报告分数的方法似乎已被弃用

以下是解决问题的代码:

  GKScore *reportScore = [[GKScore alloc] initWithLeaderboardIdentifier:@"leaderBoardI"]; reportScore.value = totalPoints; NSArray *scores = @[reportScore, nil]; [GKScore reportScores:scores withCompletionHandler:nil];