遊戲中心有緩存機制可以離線使用嗎?遊戲中心是否有可能在離線模式下收集分數,當網絡狀態變爲在線時,它會將分數提供給服務器?是否可以在離線模式下閱讀下載的分數?遊戲中心如何離線工作?
如果上述問題的答案都是NO,有沒有可以爲我們做這個的庫?
感謝您的任何幫助。
遊戲中心有緩存機制可以離線使用嗎?遊戲中心是否有可能在離線模式下收集分數,當網絡狀態變爲在線時,它會將分數提供給服務器?是否可以在離線模式下閱讀下載的分數?遊戲中心如何離線工作?
如果上述問題的答案都是NO,有沒有可以爲我們做這個的庫?
感謝您的任何幫助。
Axeva的答案不正確 - GKLocalPlayer沒有這樣的方法定義爲 「resubmitStoredScores」。相反,此方法在Apple的iOS開發者庫中提供的example code中進行了定義和實現,該開發人員庫演示了GameKit排行榜的使用。
如果你不想從蘋果的例子中複製代碼,那裏有幾個庫。一些谷歌搜索打開了以下擊中github.com:
如果這些都不滿足您的需求,你需要實現你自己的解決方案。
是的,Game Center會緩存分數。對於您在應用程序委託的didFinishLaunchingWithOptions中調用的GKLocalPlayer對象,有一個resubmitStoredScores方法。
下面是一個例子:
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
if (localPlayer.isAuthenticated) {
// Enable Game Center Functionality
self.gameCenterAuthenticationComplete = YES;
if (! self.currentPlayerID || ! [self.currentPlayerID isEqualToString: localPlayer.playerID]) {
[[NSUserDefaults standardUserDefaults] setBool: NO forKey: kGameInProgress];
// Switching Users
if (!self.player || ![self.currentPlayerID isEqualToString: localPlayer.playerID]) {
// If there is an existing player, replace the existing PlayerModel object with a
// new object, and use it to load the new player's saved achievements.
// It is not necessary for the previous PlayerModel object to writes its data first;
// It automatically saves the changes whenever its list of stored
// achievements changes.
self.player = [[[PlayerModel alloc] init] autorelease];
}
[[self player] loadStoredScores];
[[self player] resubmitStoredScores];
}
} else {
// User has logged out of Game Center or can not login to Game Center, your app should run
// without GameCenter support or user interface.
self.gameCenterAuthenticationComplete = NO;
}
}];