0

I am making a game app with game center.

I would like to ask what is the good practice for saving game data like whole object (GKTurnBasedMatch) in app?

Since, there is matchData for each of the match. I am planning to save this GKTurnBasedMatch in NSDefault , however no luck for retrieving it from the nsdefault. So, is there any good way to do so ?

Could you guys please give me some advises? my consideration is only what if i update the app , would NSDefault data be deleted after the app update?

justicepenny
  • 2,004
  • 2
  • 24
  • 48

1 Answers1

2

It's not good practice to store these objects at all. The "truth" for Game Kit is at Game Center, so your app should be retrieving the latest information from Game Center to ensure everything's up to date. Imagine if your user has two different devices, and makes progress on a game on one device; if the other device is relying on shared state then it would miss out on the updates.

When your app launches, use +[GKTurnBasedMatch loadMatchesWithCompletionHandler:] to find out what matches are currently in progress. If you need to store custom data with the matches, store it in the matchData property on the match so that it's synced with Game Center.

If you want to support some kind of limited offline display, I'd take the properties you need to be able to show and store those associated with the match ID (so you can match it back to a live match when you get reconnected to Game Center. For example, you could store the match participants' names and the current message. Those are all just strings, so you could easily them with the match ID in user defaults.

  • yes you are right, but what I am trying to do is , when the user has no internet, i need to show the latest match to them. that why i need to save it in the app. do you have any ideas? – justicepenny May 08 '13 at 11:41
  • if my matchData is a NSDictionary, where would you save this in app? NSDefault or Coredata? – justicepenny May 08 '13 at 12:17
  • @justicepenny that depends on the design of your app, there's no reason you couldn't store it in NSUserDefaults. –  May 08 '13 at 12:25