Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Game Center GKTurnBasedMatch problems with matchData property

I'm creating a Game Center game with GKTurnBasedMatch matches. I'm having a problem where the readonly matchData property on a GKTurnBasedMatch does not seem to be properly stored on Game Center servers.

I'm using this StackOverflow answer to generate an md5 checksum on the matchData NSData, both when being sent and received to and from the Game Center servers.

I note the checksum of my NSData game data object when I send the matchData using the GKTurnBasedMatch instance method endTurnWithNextParticipants:turnTimeout:matchData:completionHandler:.

The opponent then retrieves the matches using GKTurnBasedMatch's class method loadMatchesWithCompletionHandler:, and when the matches arrive (no errors), I note the checksum again.

The two checksums do not match, and the resulting data are clearly not identical based on the reconstructed game. I have checked in the two accounts that the matchID property on my GKTurnBasedMatch objects are identical.

I've also performed the following test:

NSLog(@"matchID: %@ matchData checksum: %@",
                    match.matchID, 
                    [Utilities md5StringFromData:match.matchData]);

// match is a valid `GKTurnBasedMatch` object.
[match endTurnWithNextParticipants: @[ opponent ] // My `GKTurnBasedParticipant` opponent
                       turnTimeout:600
                         matchData:data // This is a valid NSData object
                 completionHandler:^(NSError *error) {
                      if (nil != error) {

                          NSLog(@"%@", error);

                      } else {

NSLog(@"Successfully ended turn.");

[GKTurnBasedMatch loadMatchesWithCompletionHandler:^(NSArray *matches, NSError *error) {

    if (nil != error) {

        NSLog(@"Error getting matches: %@", [error localizedDescription]);

    } else {

        for (GKTurnBasedMatch *match in matches) {

            NSLog(@"matchID: %@ matchData checksum: %@", 
                        match.matchID, 
                        [Utilities md5StringFromData:match.matchData]);

        }

    }
}];

                      }
}];

In this sample, where I end the turn with data and immediately retrieve the matches from Game Center, the data match. However, when I access the matchData from the opponent's Game Center account and device, they differ.

Anyone encountered anything like this?

like image 680
Tim Arnold Avatar asked Feb 06 '13 17:02

Tim Arnold


1 Answers

I discovered the solution on Apple's Dev Forums.

It turns out that loadMatchesWithCompletionHandler: doesn't always grab the most up-to-date matchData. To make sure you have the most recent version, make sure you call the loadMatchDataWithCompletionHandler: method on your GKTurnBasedMatch object.

like image 134
Tim Arnold Avatar answered Oct 04 '22 15:10

Tim Arnold