2010-10-06 68 views
7

我使用下面的函數來提交比分遊戲中心。如何修改下面的代碼,以便只有比已提交的分數高時才能發送分數?我不想在本地維護分數。任何幫助?iPhone gamecenter提交最高分?

- (void) reportScore: (int64_t) score forCategory: (NSString*) category 
{ 
GKScore *scoreReporter = [[[GKScore alloc] initWithCategory:category] autorelease]; 
scoreReporter.value = score; 
[scoreReporter reportScoreWithCompletionHandler: ^(NSError *error) 
    { 
    [self callDelegateOnMainThread: @selector(scoreReported:) withArg: NULL error: error]; 
    }]; 
} 

謝謝。

編輯:我剛剛發現它僅由遊戲中心處理......只有最高分纔會顯示在gamecenter應用程序中。

+0

我想我們需要更多的信息。 – 2010-10-06 12:58:49

+0

例如。如果我打電話給[Myclass reportScore:1000 forCategory:@「easymode」];下次如果我打電話給[Myclass reportScore:10 forCategory:@「easymode」];提交的分數將爲10而不是1000.那麼,如何獲得以前上傳的分數,以便只有當currentscore比以前大時我才能上傳分數。 – 2010-10-06 13:09:53

回答

3

您可以檢索使用

GKLeaderboard *query = [[GKLeaderBoard alloc] initWithPlayerIDs:[NSArray arrayWithObject:yourPlayerId]]; 

if (query != nil) 

{ 

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

     if (error != nil) 

      // handle the error. 

     if (scores != nil) 

      // process the score information. 

     }]; 

} 

獲得更多信息之前的得分Apple GameKit Programming Guide