0

所以我有一些问题,我已经尝试解决它们大约两天了。

我设置了 2 个沙盒帐户,并在模拟器和我的设备上试用了该应用程序。

游戏中心验证帐户/登录您。

但是一次只显示一个帐户分数,我不知道为什么。第二。而不是将分数显示为 1 分、2 分等,这个数字真的是错误的。例如。

分数应该是三的地方,写着“392,868,960”甚至更大!

有谁知道这到底是为什么以及我如何解决它。此外,在 xcode 中,当我测试播放我的应用程序时,底部没有反馈。例如,NSLOG 语句!

任何帮助将非常感激。我使用的代码如下。提前非常感谢。

-(void)authentication //log player into game centre
{
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) {
            NSLog(@"authentication successful");
            GameCenterAvailable = YES;
            [[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier, NSError *error) {

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

        else{
            NSLog(@"authentication unsuccessful");
            GameCenterAvailable = NO;
        }


       }
    };
}

-(void)submitScore{

    if (ScoreNumber > HighScoreNumber) {

    GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:@"Dodge_Leaderboard"] autorelease];

    scoreReporter.value = [[NSNumber numberWithInt:ScoreNumber] longLongValue];
    NSLog(@"posted");
    NSLog(@"%i",ScoreNumber);

    [scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
        if (error != nil)
        {
            NSLog(@"failed!");
            NSLog(@"%i",ScoreNumber);
        }
        else{
            NSLog(@"Succeeded");

        }
    }];}}

-(IBAction)ShowGameCenter:(id)sender //show game center
{
    GKLeaderboardViewController *LeaderboardController = [[GKLeaderboardViewController alloc] init];
    if (LeaderboardController != nil) {
        LeaderboardController.leaderboardDelegate = self;
        [self presentViewController:LeaderboardController animated:YES completion:nil];
    }
}

//Animate gc out if finished with it

-(void)leaderboardViewControllerDidFinish: (GKLeaderboardViewController *) viewController{
    [self dismissViewControllerAnimated:YES completion:nil];
}

提交分数的新代码:

-(void)reportScore { if ([GKLocalPlayer localPlayer].isAuthenticated) { GKScore *scoreReporter = [[GKScore alloc] initWithLeaderboardIdentifier:@"Dodge_Leaderboard" forPlayer:[GKLocalPlayer localPlayer].playerID]; scoreReporter.value = ScoreNumber; NSLog(@"得分报告值:%@", scoreReporter); [GKScore reportScores:@[scoreReporter] withCompletionHandler:^(NSError *error) { if (error != nil) { NSLog(@"Error"); // 处理报告错误 }

    }];
}}
4

0 回答 0