1

How do I identify if multi-player game is initiated by automatch or by inviting a friend ?

I have got this method called when the match starts:

- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)theMatch {

    [presentingViewController dismissModalViewControllerAnimated:YES];
    self.match = theMatch;
    match.delegate = self;
    if (!matchStarted && match.expectedPlayerCount == 0) {
        NSLog(@"Ready to start match!");
        [self lookupPlayers];
    }
}

Basically i want this(please check this link) - how to sync data in multiplayer game(game-center ios)

Community
  • 1
  • 1
  • 1
    Please check the comment of this answer, using timestamps seems to be the most reasonable solution to choose the host at "automatch": http://stackoverflow.com/a/12741018/792677 And in case I would only need to pick the map as at the question you quoted, I'd rather make it as a vote. – A-Live Dec 11 '12 at 13:26
  • Please feel free to post an answer or update the question if needed. – A-Live Dec 13 '12 at 06:27

1 Answers1

2

I check if the local player's playerID is contained in the match's list of participants. I have found they are not be listed if they were invited or auto matched. I believe this is because they have not yet accepted the match.

+ (BOOL) isLocalPlayerActiveParticipantInMatch:(GKTurnBasedMatch *)aMatch
{
    for (GKTurnBasedParticipant *participant in aMatch.participants)
    {
        if ([participant.playerID isEqualToString:[GKLocalPlayer localPlayer].playerID])
            return YES;
    }

    return NO;
}

If the payer decides to play the match, I call this for the match:

GKTurnBasedMatch acceptInviteWithCompletionHandler

If they decline, I call this for the match:

GKTurnBasedMatch declineInviteWithCompletionHandler
Jay Haase
  • 1,979
  • 1
  • 16
  • 36