GKLeaderboard发布问题

时间:2011-06-24 01:55:55

标签: ios4 gamekit

我不确定沙盒是否花费太长时间来更新或者我的代码是否很时髦。

我只是抓住当地球员最后输入的分数并为其添加另一个分数并尝试发布结果。

这是我的代码:

- (void) reportScore: (int64_t) score forCategory: (NSString*) category
{
GKScore *scoreReporter = [[[GKScore alloc]initWithCategory:category] autorelease];
scoreReporter.value = score;

[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
    if (error != nil)
    {
        // handle the reporting error
        NSLog(@"Error reporting score");

    }
}];
}

-(void)postScore:(int64_t)score forCategory:(NSString *)category {

GKLeaderboard *query = [[GKLeaderboard alloc]init];
query.category = category;

if (query != nil)

{

    [query loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error) {

        if (error != nil){

            // Handle the error.
            NSLog(@"Error loading scores");

        }
        if (scores != nil){

            // Process the score.

            int64_t newScore = query.localPlayerScore.value + score;

            [self reportScore:newScore forCategory:category];


        }



    }];


}

[query release];
}

感谢您的帮助。

编辑:沙盒排行榜有第一个分数,但不会更新后续分数。

2 个答案:

答案 0 :(得分:1)

在我的结尾有同样的问题。它将在会话中第一次正确提供分数。之后,即使我们更新该会话中的分数,它也会继续发送相同的分数。

答案 1 :(得分:0)

您需要检查GKleaderBoard类的属性。对于您的信息。见下面的代码。

GKLeaderboardViewController * leaderController = [[GKLeaderboardViewController alloc] init];

     if (leaderboardController != NULL)
     {
        leaderController.category = self.currentLeaderBoard;
        leaderController.timeScope = GKLeaderboardTimeScopeWeek;
        leaderController.leaderboardDelegate = self;
        [self presentModalViewController: leaderController animated: YES];
     }

                                AND

您还可以查看以下GKLeaderBoard和GKAchievementViewController课程的Apple文档。

GKLeaderBoard的

http://developer.apple.com/library/ios/#documentation/GameKit/Reference/GKLeaderboard_Ref/Reference/Reference.html

用于GKAchievementViewController http://developer.apple.com/library/ios/#documentation/GameKit/Reference/GKAchievementViewController_Ref/Reference/Reference.html