Xcode-将分数提交给GameCenter

时间:2012-04-22 16:41:21

标签: ios xcode center game-center

我有这个代码用于将我的分数提交给游戏中心但是每当我在游戏中心内提交分数时它表示我的分数是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";

1 个答案:

答案 0 :(得分:0)

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

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