Let me look at the problems you see here. Firstly, there is no need to set the playersToInvite property to nil, since this is the default state if no players are assigned, but this does not cause your problem. I put this in quotation marks because you actually did the code correctly and only perceived the problem, which was not there. Let me tell you what happens when findMatchForeRequest is complete.
When the completion block is called, Game Center created a new GKTurnBasedMatch object with two participants, the first of which is the local player (you), and the second is the empty participant with the identifier nil. The reason for this is that Game Center does not appoint all participants when a match is created with random (unassigned) opponents. A random participant is assigned when a queue is sent to them. In your game, this match will not appear in the cloud so that others can play until you make your first turn.
Now, calling loadMatchesWithCompletionHandler on your other device / Game Center Identifier will not automatically display a match IF you have not specifically invited this player with ToInvite players (and already made your move, as indicated above). Think of it this way: if it worked, every player in the world would see every auto-negotiation when they call loadMatchesWithCompletionHandler.
The identifier of the other game center should actually call findMatchForRequest without the playersToInvite property set, in order to be matched with the free space available in the game, your other identifier. Thus, the paradigm is βalways your turnβ when creating a match, but this player is now in the second slot, and not in the first. Just create a game on the second identifier in the same way as on the first one, and your game will be created with two participants, the first of which will be initially created, and the second - an identifier that joined the match by calling findMatchForRequest. The key here is findMatchForRequest, do NOT ALWAYS create a new match if playerToInvite is zero. If there is an existing match with an open space, it will simply match the local player.
Happy coding!
Corbin
source share