2013-10-16 56 views
5

根據https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/LeaderBoards/LeaderBoards.html報告分數的GameCenter的ios7

報告分數的GameCenter在ios7應該使用

[GKLeaderboard reportScores:scores withCompletionHandler:^(NSError *error) { 
//Do something interesting here. 
}]; 

但是做,我找不到在GKLeaderboard這種方法的任何引用。

方法,這裏不存在: https://developer.apple.com/library/ios/documentation/GameKit/Reference/GKLeaderboard_Ref/Reference/Reference.html

GKLeaderboard.h不包含reportScores法也。

以前使用GKScore報告的ScoreWithCompletionHandler方法報告分數的方式已被棄用,所以我不願意使用它。

有沒有人知道什麼是正確的方式來報告分數到gamecenter在ios7?

回答

15

我可以確認reportScores:withCompletionHandler:方法有效;我在我的一個應用程序中使用它。它位於頭文件GKScore.h中。這是我如何使用它:

- (void) reportHighScore:(NSInteger) highScore { 
    if ([GKLocalPlayer localPlayer].isAuthenticated) { 
     GKScore* score = [[GKScore alloc] initWithLeaderboardIdentifier:MY_LEADERBOARD_ID]; 
     score.value = highScore; 
     [GKScore reportScores:@[score] withCompletionHandler:^(NSError *error) { 
      if (error) { 
       // handle error 
      } 
     }]; 
    } 
} 
+1

感謝您指出這一點,顯然實例方法已被棄用,但類方法沒有。我現在將使用這種方法。在蘋果的開發參考中,他們將iOS 6和7之間的例子分開,所以我相信他們打算以不同的方式完成。奇怪的是,iOS7的預期方式沒有正確記錄。 – Cymric

+0

有時Apple的文檔是錯誤的。我傾向於相信類文檔中的內容比概述中的內容更多。 https://developer.apple.com/library/ios/documentation/GameKit/Reference/GKScore_Ref/Reference/Reference.html#//apple_ref/occ/clm/GKScore/reportScores:withCompletionHandler: – Greg

+0

我也遇到過這個問題。看起來蘋果需要在發佈它們之前仔細閱讀它們的文檔,因爲它會造成很多混亂和浪費時間... – Pupillam