Search code examples
iosgamekit

How does a player programmatically using GameKit advertise they want to join some match?


I am having trouble finding information in the standard GameKit documentation on how does a player advertise that they want to join some match? There is documentation on how to create a match and invite waiting players, but I can't decipher how does a player advertise to join a match and become this "waiting" player?

Here is a link to Apple's documentation https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/GameKit_Guide/MatchmakingwithGameCenter/MatchmakingwithGameCenter.html


Solution

  • Calling findMatch on a GKMatchmaker will probably do the trick:

    https://developer.apple.com/documentation/gamekit/gkmatchmaker/1520777-findmatch

        // Auto-matching or invites to find a peer-to-peer match for the specified request. Error will be nil on success:
        // Possible reasons for error:
        // 1. Communications failure
        // 2. Unauthenticated player
        // 3. Timeout
        // Note that the players property on the returned GKMatch instance will only contain connected players. It will initially be empty as players are connecting. Implement the GKMatchDelegate method match:player:didChangeConnectionState: to listen for updates to the GKMatch instance's players property.
    
        open func findMatch(for request: GKMatchRequest, withCompletionHandler completionHandler: ((GKMatch?, Error?) -> Void)? = nil)