【问题标题】:Game Centre - Submitting to a Non-Default LeaderboardGame Center - 提交到非默认排行榜
【发布时间】:2015-06-07 22:15:01
【问题描述】:

所以我有一个具有Game AGame B 的应用程序。

我已经为游戏 A 正确实现了游戏中心(我使用了 AppCoda tutorial,就像目前为止的每款游戏一样)。

现在,如果玩游戏 B,我无法提交分数。我需要将分数提交到在 iTunes Connect 中创建的第二个排行榜。

这是我的 ViewController 的一部分,用于验证用户并使用排行榜等的标识符。

ViewController.h:

-(void)authenticateLocalPlayer{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];

localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
    if (viewController != nil) {
        [self presentViewController:viewController animated:YES completion:nil];
    }
    else{
        if ([GKLocalPlayer localPlayer].authenticated) {
            _gameCenterEnabled = YES;                                   //added bool indentier to .h

            // Get the default leaderboard identifier.
            [[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier, NSError *error) {

                if (error != nil) {
                    NSLog(@"%@", [error localizedDescription]);
                }
                else{
                    _leaderboardIdentifier = leaderboardIdentifier;     //added pointer to NSString to .h
                }
            }];
        }

        else{
            _gameCenterEnabled = NO;
        }
    }
};

}

似乎我的游戏 B 视图控制器正在评分/提交就像游戏 A,我想我可以将上面的代码更改为:(以允许第二个标识符):

-(void)authenticateLocalPlayer{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];

localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
    if (viewController != nil) {
        [self presentViewController:viewController animated:YES completion:nil];
    }
    else{
        if ([GKLocalPlayer localPlayer].authenticated) {
            _gameCenterEnabled = YES;                                   //added bool indentier to .h
            _gameCenterEnabled2 = YES;

            // Get the default leaderboard identifier.
            [[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier, NSError *error) {

                if (error != nil) {
                    NSLog(@"%@", [error localizedDescription]);
                }
                else{
                    _leaderboardIdentifier = leaderboardIdentifier;     //added pointer to NSString to .h
                }
            }];

            // Get the second leaderboard identifier.
            [[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier2, NSError *error) {

                if (error != nil) {
                    NSLog(@"%@", [error localizedDescription]);
                }
                else{
                    _leaderboardIdentifier2 = leaderboardIdentifier2;     //added pointer to NSString to .h
                }
            }];


        }

        else{
            _gameCenterEnabled = NO;
            _gameCenterEnabled2 = NO;
        }
    }
};

}

但由于某种原因,它不会将分数发送到第二个排行榜,而且我找不到任何关于如何将分数提交到“非默认”排行榜的资源/教程...

【问题讨论】:

    标签: ios objective-c game-center


    【解决方案1】:

    好的,所以我重新阅读了 Apple Doc 并找到了解决方案。

    显然只能有一个默认排行榜(在我的问题中的代码中经过身份验证和设置)......这不需要像我最初想的那样改变。 (我忘了它是用来设置默认板的)。

    所以我需要做的是将排行榜标识符设置为第二个排行榜的标识符(这将是您在制作第二个排行榜时在 iTunes Connect 中使用的任何 ID)。

    我在 Game B 视图控制器中报告这样的分数时这样做了:

    -(void)reportScore{
    
    //set identifier manually as it's not the default leaderboard
    GKScore *score = [[GKScore alloc] initWithLeaderboardIdentifier:@"The_GameB_Leaderboard"];
    //GKScore *score = [[GKScore alloc] initWithLeaderboardIdentifier:_leaderboardIdentifier2];
    
    score.value = ScoreNumber_B; //Game B HighScore
    
    [GKScore reportScores:@[score] withCompletionHandler:^(NSError *error) {
        if (error != nil) {
            NSLog(@"%@", [error localizedDescription]);
        }
    }];
    NSLog(@"Reported to Game Center...");
    

    }

    没有必要更改-(void)authenticateLocalPlayer方法,除非你需要像我一样添加GameB bool,在这种情况下你可以在GameA Bool下面添加它:

    if ([GKLocalPlayer localPlayer].authenticated) {
            _gameCenterEnabled = YES;      //added bool indentier to .h
            _gameCenterEnabled2 = YES;     //GameB bool
        .
        .
        .
    }
    

    我希望这会有所帮助。

    【讨论】:

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