iOS Developer Library

Developer

GameKit Framework Reference GKMatchmakerViewControllerDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

GKMatchmakerViewControllerDelegate

A class implements the GKMatchmakerViewControllerDelegate protocol to receive notifications from a GKMatchmakerViewController object. The delegate is called if a new match has been successfully created, if the user cancels matchmaking, and if an error occurs. In all three cases, the delegate should dismiss the view controller.

  • Called when a peer-to-peer match is found.

    Declaration

    Swift

    optional func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFindMatch match: GKMatch)

    Objective-C

    - (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match

    Parameters

    viewController

    The view controller that performed the matchmaking.

    match

    A completed match.

    Discussion

    This method is called when the view controller’s hosted property is NOfalse. Although optional in the protocol, if your game attaches a delegate to the view controller for a peer-to-peer match, the view controller expects your game to provide an implementation of this method.

    Listing 1 shows a possible implementation of the delegate method. This method assigns the match object to a property on the object and then adds the object as the match object’s delegate. At this stage of the process, all the players have been found, but it is possible for the match object to be returned before all players are successfully connected. If all the players are already connected to the match, the game recognizes this and immediately begins the match. Otherwise, it does nothing; the match delegate starts the match when the last player connects.

    Listing 1Implementing the match found method
    1. - (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match
    2. {
    3. [self dismissViewControllerAnimated:YES completion:nil];
    4. self.myMatch = match; // Use a retaining property to retain the match.
    5. match.delegate = self;
    6. if (!self.matchStarted && match.expectedPlayerCount == 0)
    7. {
    8. self.matchStarted = YES;
    9. // Insert game-specific code to start the match.
    10. }
    11. }

    Availability

    Available in iOS 4.1 and later.

  • Called when a hosted match is found.

    Declaration

    Swift

    optional func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFindHostedPlayers players: [GKPlayer])

    Objective-C

    - (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindHostedPlayers:(NSArray<GKPlayer *> *)players

    Parameters

    viewController

    The view controller that performed the matchmaking.

    players

    An array of GKPlayer objects containing the player identifier for the matched players.

    Discussion

    This method is called when the view controller’s hosted property is YEStrue. Although optional in the protocol, if your game attaches a delegate to the view controller for a hosted match, the view controller expects your game to provide an implementation of this method.

    The view controller returns the list of players to your game by calling this method. Your game is responsible for connecting these players to your own server and then using that server to relay messages between the players.

    Availability

    Available in iOS 8.0 and later.

  • Called when a hosted match is found.

    Declaration

    Swift

    optional func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFindPlayers playerIDs: [String])

    Objective-C

    - (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindPlayers:(NSArray<NSString *> *)playerIDs

    Parameters

    viewController

    The view controller that performed the matchmaking.

    playerIDs

    An array of NSString objects containing player identifier for the matched players.

    Discussion

    This method is called when the view controller’s hosted property is YEStrue. Although optional in the protocol, if your game attaches a delegate to the view controller for a hosted match, the view controller expects your game to provide an implementation of this method.

    The view controller returns the list of players to your game by calling this method. Your game is responsible for connecting these players to your own server and then using that server to relay messages between the players.

    Availability

    Available in iOS 4.1 and later.

    Deprecated in iOS 8.0.