1

スコアをゲーム センターに送信するためのこのコードがありますが、ゲーム センター内でスコアを送信するたびに、スコアが 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";
4

1 に答える 1

0

参考までに、あなたのスコアは?

古いスコアと新しいスコアを読み込むには、2 つの異なる変数が必要です。新しいスコアが古いスコアよりも大きい場合は、その if ステートメントを true に設定する必要があります。ゼロより大きい値に設定すると、ユーザーのスコアが 0 より大きいたびに常に変化します。

于 2014-02-18T19:22:51.700 に答える