【问题标题】:How to implement Game Center Leaderboards in iOS 7?如何在 iOS 7 中实现 Game Center 排行榜?
【发布时间】: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


【解决方案1】:

您是否在 iTunes Connect 中的应用程序中添加了排行榜信息并提交了您的应用程序,以便状态为等待二进制上传?您可能还需要在设置应用状态后等待 24 小时,然后才能使用新排行榜的沙盒版本。

您需要确保为您提交的应用程序版本启用 Game Center 组件(排行榜和成就),这与您在 iTunes Connect 中创建排行榜的区域是分开的。

【讨论】:

    【解决方案2】:

    您确定要在同一个班级初始化和更新分数吗? 如果您在应用委托中初始化但在其他类中上传分数,则可能会产生问题,例如如下所示:

    您在应用委托中验证了播放器:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    
    {
    
    if ([GameCenterManager isGameCenterAvailable])
    
    {
    
        isGameCenterAvailable = YES;
        self.gameCenterManager = [[[GameCenterManager alloc] init] autorelease];
        [self.gameCenterManager setDelegate:self];
        [self.gameCenterManager authenticateLocalUser];
        }
    else
        {
        isGameCenterAvailable = NO;
        // The current device does not support Game Center.
        }
    

    然后想上传其他类的分数,使用app delegate的对象:

    - (void) submitScore2 : (int) curScore
    {
        if(curScore > 0)
        {
        [[self delegate].gameCenterManager reportScore: curScore forCategory: self.currentLeaderBoard];
        }
    }  
    

    【讨论】:

      猜你喜欢
      • 2014-12-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多