Search code examples
iosgame-centergamekitios6.1

Gamecenter matchdata does not get updated


I have a strange problem with GameKit. I would like to know if some other people experience the same problem. Is it a bug?

I have implemented a basic turn based game using game kit. A Player invites another one

+ (void)findMatchForRequest:(GKMatchRequest *)request withCompletionHandler:(void (^)(GKTurnBasedMatch *match, NSError *error))completionHandler

and ends turn

- (void)endTurnWithNextParticipants:(NSArray *)nextParticipants turnTimeout:(NSTimeInterval)timeout matchData:(NSData *)matchData completionHandler:(void (^)(NSError *error))completionHandler

The second player accepts and the game begins. After the second player has played his turn he ends turn

- (void)endTurnWithNextParticipants:(NSArray *)nextParticipants turnTimeout:(NSTimeInterval)timeout matchData:(NSData *)matchData completionHandler:(void (^)(NSError *error))completionHandler

and so on...

The players receives notifications even with custom message, everything works well.

It works also when the app (other player) is in background and I launched the app by tapping on notification banner.

The problem appears when the app runs in background on a device and the other device ends the turn. The first device gets notification about turn but when I launch the app (not by tapping on notification banner, just manually) and load matches I get the old match data.

+ (void)loadMatchesWithCompletionHandler:(void (^)(NSArray *matches, NSError *error))completionHandler

I do not persist any game data in my app, just transient objects. I have tried close the apps on both devices and load matches again. They get different match data from the server of game center. One of them gets old data and the other one, which has ended the turn, the updated match data.

I have tried the same thing with the following method, and it works but with that I can not end the turn.

- (void)saveCurrentTurnWithMatchData:(NSData *)matchData completionHandler:(void (^)(NSError *error))completionHandler

While I am testing I do not use simulator, only devices. SDK 6.1, iOS 6.0.1 and of course sandbox.


Solution

  • The loadMatchesWithCompletionHandler: call only gets the meta data of the matches, like who is playing, what the state of the game is, etc. Essentially what information you'd display in an overview view controller.

    To get an up to date version of the match data blob, call loadMatchDataWithCompletionHandler: on the GKTurnBasedMatch object prior to displaying the game. At some points this also has to be done after sending a turn or ending a match!