排行榜集成无法正常工作

时间:2014-03-10 15:41:59

标签: ios objective-c game-center leaderboard

我正在为iOS 7创建游戏,并且正在尝试实施Game Center排行榜。当我点击某个按钮时,我得到了打开排行榜的应用程序,但它显示“没有项目”。如果提交分数或检索排行榜存在问题,我现在不确定。提交分数似乎是一个问题,因为它在我的排行榜顶部显示了应用名称,但我找不到我的错误。我提交分数的代码:

-(void)reportScore:(NSInteger ) highScore {
if ([GKLocalPlayer localPlayer].isAuthenticated) {
    GKScore *scoreReporter = [[GKScore alloc]  initWithLeaderboardIdentifier:@"flapjacks1" forPlayer:[GKLocalPlayer localPlayer].playerID];
scoreReporter.value = highScore;
    NSLog(@"Score reporter value: %@", scoreReporter);
[GKScore reportScores:@[scoreReporter] withCompletionHandler:^(NSError *error) {
    if (error != nil) {
        NSLog(@"Error");
     // handle the reporting error
     }

}];
}

}

这是我检索排行榜的方法:

-(void)displayLeaderboard
{
//NSString *_leaderboardIdentifier = @"flapjacks1";
[[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier, NSError *error) {

    if (error != nil) {
        NSLog(@"%@", [error localizedDescription]);
    }
    else{
        //_leaderboardIdentifier = leaderboardIdentifier;
        GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];
        if (gameCenterController != nil)
        {
            gameCenterController.gameCenterDelegate = self;
            gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
            //gameCenterController.leaderboardTimeScope = GKLeaderboardTimeScopeToday;
            gameCenterController.leaderboardIdentifier = @"flapjacks1";
            [self presentViewController: gameCenterController animated: YES completion:nil];
        }
    }

}];

}

0 个答案:

没有答案