I'm trying to use game center : multi player
Till now, players are Authenticating to Game center, they can send/read scores, and acheivements. For multiplayer features, I tried both methods : - using Game center interface to find a match. - Find a Match Programmatically.
For both ways I have the following issue: the match delegate’s match:player:didChangeState: method is not called. In apple docs, it's stated that this delegate is called if one player is connected or disconnected.
In my case this delegate is never called. I think that I'm missing a step. here after the implementation of my delegate (as specified in apple doc).
- (void)match:(GKMatch *)match player:(NSString *)playerID didChangeState:(GKPlayerConnectionState)state
{
switch (state)
{
case GKPlayerStateConnected:
// handle a new player connection.
break;
case GKPlayerStateDisconnected:
// a player just disconnected.
break;
}
if (!self.matchStarted && match.expectedPlayerCount == 0)
{
self.matchStarted = YES;
// handle initial match negotiation.
}
}
and also the code to find a match.
-(void) findProgrammaticMatch
{
GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease];
request.minPlayers = 2;
request.maxPlayers = 2;
[[GKMatchmaker sharedMatchmaker] findMatchForRequest:request
withCompletionHandler:^(GKMatch *FoundMatch, NSError *error)
{
if (error)
{
// Process the error.
StatusLabel.text = @"Match Not Found";
}
else if (FoundMatch != nil)
{
MultiPlayerMatch = FoundMatch; // Use a retaining property to retain the match.
StatusLabel.text = @"Match Found";
MultiPlayerMatch.delegate = self; // start!
// Start the match.
// Start the game using the match.
[self StartMatch];
}
}];
}
Thanks for your help.