游戏中心如何脱机工作?

时间:2013-01-10 14:12:22

标签: ios game-center

游戏中心是否有可以脱机使用的缓存机制?游戏中心是否有可能在离线模式下收集分数,当网络状态更改为在线时,它会将分数传递给服务器?是否可以在离线模式下阅读下载的分数?

如果上述问题的答案为否,是否有可以为我们执行此操作的库?

感谢您的帮助。

2 个答案:

答案 0 :(得分:4)

Axeva的答案不正确 - GKLocalPlayer没有定义“resubmitStoredScores”这样的方法。相反,此方法是在Apple的iOS开发人员库中提供的example code中定义和实现的,该库演示了GameKit排行榜的使用。

如果您不想从Apple的示例中复制代码,那么有一些库。一些谷歌搜索在github.com上发现以下点击:

  • /安东-尼堪/ IOS的​​游戏 - 中 - 高速缓存
  • / csddavies / DDGameKitHelper

如果这些都不能满足您的需求,您需要实施自己的解决方案。

答案 1 :(得分:1)

是的,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;
        }
    }];