Reputation: 18159
- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match
{
self.myMatch = match;
NSLog(@"%d",[[self.myMatch playerIDs]count]);
}
But my console returns 0. Shouldn't it return 2 instead?
Upvotes: 1
Views: 1842
Reputation: 12296
Could it be that you are not actually connecting them?
Are you in fact using GKMatchmaker
and GKMatchmakerViewController
?
In your testing, you are sure you are using TWO DIFFERENT game center accounts?
I'm afraid I'm not familiar with the game center system.
Upvotes: 2
Reputation: 33602
GKMatchmaker returns you a match before connections have been established between players; at this stage, all the players are in the process of connecting to each other.
The playerIDs property is initially set to the number of players already connected to the match; the array may be empty. Whenever a player is connected to the match, that player’s player identifier is added to the array.
Additionally, some players can fail to connect (I haven't tested this case so I don't know if you get an error returned)
What you're looking for is GKMatch.expectedPlayerCount
The value of this property is decremented whenever a player connects to the match. When its value reaches zero, all expected players are connected, and your game can begin the match.
I also suspect that GKMatch.playerIDs
does not include the player; i.e. you'll probably see expectedPlayerCount = 1 immediately after connecting.
I'm not sure what GameKit does about threads.
Upvotes: 4