【问题标题】:Xcode-Submit score to GameCenterXcode-提交分数到GameCenter
【发布时间】:2012-05-03 10:25:40
【问题描述】:

我有此代码用于将我的分数提交到游戏中心,但是每当我在游戏中心内提交分数时,它显示我的分数为 0。我不确定这是怎么发生的?我还导入了 GameKit 框架。

-(IBAction)submitScore{
    if (highscore>0) {
        GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:@"MyLeaderBoardID"] autorelease];

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

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

我也有这个登录代码:

[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
    if (error == nil) {
        NSLog(@"authintication success");
    } else {
        NSLog(@"authintication failed");
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Game Center Disabled"
                                                        message:@"For Game Center make sure you have an account and you have a proper device connection."
                                                       delegate:self
                                              cancelButtonTitle:@"Ok"
                                              otherButtonTitles:nil];
        [alert show];
    }
}];

self.currentLeaderBoard = @"MyLeaderBoardID";

【问题讨论】:

    标签: ios xcode center game-center


    【解决方案1】:

    仅供参考,你的分数是多少?

    您应该在旧乐谱和新乐谱中读取两个不同的变量。如果您的新分数大于旧分数,则您希望将该 if 语句设置为 true。将其设置为大于零将使其在每次用户得分大于 0 时不断变化。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-02
      相关资源
      最近更新 更多