1

我昨天发布了我的应用程序,到目前为止售出的单位很少。但我发现排行榜无法正常工作。我只有在完成游戏后才能看到自己的得分。在排行榜更新之前是否存在某种延迟,或者我的实施是否存在问题?如果我让知道如何正确执行的人检查我的实施,我将非常感激。附带说明一下,我已经在 iTunes-connect 上配置了我的排行榜并启用了它。我不确定GKLocalPlayer是否instance method loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier, NSError *error)是用于加载正确的 leaderboardID 的正确方法。我是否必须在 Xcode 上使用我在 iTunes-connect 上创建的排行榜 ID 手动声明我的排行榜 ID?因为我觉得奇怪的是我从来没有在实际的实现中使用它……我希望尽快修复这个错误,我需要你们的帮助。谢谢。

(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;
                NSLog(@"authenticated");
                // Get the default leaderboard identifier.
                [[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier, NSError *error) {

                    if (error != nil) {
                        NSLog(@"here");
                        NSLog(@"%@", [error description]);
                    }
                    else{
                        _leaderboardIdentifier = leaderboardIdentifier;
                    }
                }];
            }

            else{
                _gameCenterEnabled = NO;
            }
        }
    };
}

- (void)reportScore:(NSNotification *) notification {
    if (_gameCenterEnabled) {
        NSDictionary *userInfo = notification.userInfo;
        NSNumber *score = [userInfo objectForKey:@"highestScore"];
        GKScore *gkscore = [[GKScore alloc]initWithLeaderboardIdentifier:_leaderboardIdentifier];
        gkscore.value = [score integerValue];
        [GKScore reportScores:@[gkscore] withCompletionHandler:^(NSError *error) {
            if (error != nil) {
                NSLog(@"%@", [error localizedDescription]);
            }
        }];
    }


}

- (void)showLeaderboard{
    GKGameCenterViewController *gcViewController = [[GKGameCenterViewController alloc] init];
    gcViewController.gameCenterDelegate = self;

    gcViewController.viewState = GKGameCenterViewControllerStateLeaderboards;
    gcViewController.leaderboardIdentifier = _leaderboardIdentifier;

    [self presentViewController:gcViewController animated:YES completion:nil];
}

- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController
{
    [gameCenterViewController dismissViewControllerAnimated:YES completion:nil];
}
4

0 回答 0