iOS Developer Library

Developer

GameKit Framework Reference GKTurnBasedMatchmakerViewControllerDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

GKTurnBasedMatchmakerViewControllerDelegate

Inheritance


Not Applicable

Conforms To


Import Statement


Swift

import GameKit

Objective-C

@import GameKit;

Availability


Available in iOS 5.0 and later.

Your game implements the GKTurnBasedMatchmakerViewControllerDelegate protocol on an object to respond to events generated by a GKTurnBasedMatchmakerViewController object.

  • Called when the player selected a match to view. (required)

    Declaration

    Swift

    func turnBasedMatchmakerViewController(_ viewController: GKTurnBasedMatchmakerViewController!, didFindMatch match: GKTurnBasedMatch!)

    Objective-C

    - (void)turnBasedMatchmakerViewController:(GKTurnBasedMatchmakerViewController *)viewController didFindMatch:(GKTurnBasedMatch *)match

    Parameters

    viewController

    The view controller that found a match.

    match

    The match that the player selected.

    Discussion

    This method is called when a match has been found or created. The match object is returned to your delegate. Typically, your game dismisses the matchmaker view controller and immediately starts its own user interface to allow the player to play a turn. The implementation in Listing 1 uses a custom segue to show the gameplay screen. The match is passed as the sender so that it can be passed as an input to the new view controller.

    Listing 1Implementing the match found method
    • - (void)turnBasedMatchmakerViewController:(GKTurnBasedMatchmakerViewController *)viewController didFindMatch:(GKTurnBasedMatch *)match
    • {
    • [self dismissViewControllerAnimated:YES completion:nil];
    • [self performSegueWithIdentifier:@"GamePlayScene" sender:match];
    • }
    • - (void )prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    • {
    • if ([segue.identifier isEqualToString:@"GamePlayScene"])
    • {
    • MyGamePlayViewController* gameVC = (MyGamePlayViewController*) segue.destinationViewController;
    • gameVC.delegate = self;
    • gameVC.match = (GKTurnBasedMatch*) sender;
    • }
    • }

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in iOS 5.0 and later.

  • Called when a player chooses to quit the match. (required)

    Declaration

    Swift

    func turnBasedMatchmakerViewController(_ viewController: GKTurnBasedMatchmakerViewController!, playerQuitForMatch match: GKTurnBasedMatch!)

    Objective-C

    - (void)turnBasedMatchmakerViewController:(GKTurnBasedMatchmakerViewController *)viewController playerQuitForMatch:(GKTurnBasedMatch *)match

    Parameters

    viewController

    The view controller that the player interacted with.

    match

    The match the player has chosen to quit.

    Discussion

    When this method is called, the player is the current participant in the match, but that player has chosen to resign the match instead of taking a turn. Your game should dismiss the view controller, set an outcome for the player, and then call the match’s participantQuitInTurnWithOutcome:nextParticipant:matchData:completionHandler: method.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in iOS 5.0 and later.

  • Called when an error occurs. (required)

    Declaration

    Swift

    func turnBasedMatchmakerViewController(_ viewController: GKTurnBasedMatchmakerViewController!, didFailWithError error: NSError!)

    Objective-C

    - (void)turnBasedMatchmakerViewController:(GKTurnBasedMatchmakerViewController *)viewController didFailWithError:(NSError *)error

    Parameters

    viewController

    The view controller that received an error.

    error

    An error object that describes the error.

    Discussion

    Your game should dismiss the view controller.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in iOS 5.0 and later.

  • Called when the player cancels matchmaking. (required)

    Declaration

    Swift

    func turnBasedMatchmakerViewControllerWasCancelled(_ viewController: GKTurnBasedMatchmakerViewController!)

    Objective-C

    - (void)turnBasedMatchmakerViewControllerWasCancelled:(GKTurnBasedMatchmakerViewController *)viewController

    Parameters

    viewController

    The view controller that the player canceled.

    Discussion

    Your game should dismiss the view controller.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in iOS 5.0 and later.