ios - "A GKScore must specify a leaderboard."

标签 ios objective-c ios7 game-center

有人在尝试将 Game Center 集成到 iOS 7 应用程序时遇到过这个错误吗?

A GKScore must specify a leaderboard.

这是失败的代码:

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 - "A GKScore must specify a leaderboard.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22273320/

相关文章:

ios - 从 CocoaTouch 库调用 NSLog

iPhone SDK - 大 UITableViewCell

iphone - Obj-C,试图从 View Controller 中删除一些代码到子类中?

objective-c - 如何防止时区更改时 NSDatePicker 时间更改

ios - 从 SQLite 数据库加载 UITableView 中的可见单元格

php - (Swift,iOS)根据 PHP 脚本中使用的 POST 变量从 mySQL 数据库解析 JSON 对象?

ios - 如何使 UITextView 检测到文本中的链接部分并且仍然有 userInteractionDisabled?

ios - RESideMenu : Side menu for iOS 7 to support both left and right menu

ios - 在 Swift 中使用 Reachability、NSNotification 和 Network Link Conditioner 检测网络连接变化

objective-c - 如何将这段 NSClassFromString 代码转换为 Swift?