2011-06-24 140 views
2

我不確定沙箱是否需要花費太長時間才能更新,或者我的代碼是否時髦。GKLeaderboard發佈問題

我只是抓住本地球員最後輸入的分數,並添加了另一個分數,並試圖發佈結果。

這裏是我的代碼:

- (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]; 
} 

感謝您的幫助。

編輯:沙箱排行榜有第一個分數,但不會更新隨後的分數。

回答

0

您需要檢查GKleaderBoard class.For屬性您的信息。見下面的代碼。

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

1

在我的結尾有同樣的問題。它會在會議中第一次正確提供分數。之後,即使我們更新了該會話中的分數,它也會繼續發送相同的分數。