【发布时间】:2014-04-13 00:30:28
【问题描述】:
我正在为 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];
}
}
}];
}
所以,我不确定我是否不正确地访问了排行榜,或者排行榜是否真的没有数据。我一直在寻找,找不到答案。非常感谢您的帮助。
【问题讨论】:
-
如果你是在沙盒模式下开发,这是一个很常见的问题。排行榜只是没有正确显示。在您的设备中打开 Game Center 应用程序并在列表中查找您的游戏 - 点击它并从那里查看排行榜。事实证明,这比在您自己的应用中查看排行榜更准确。
标签: ios objective-c ios7 game-center leaderboard