In my application, the player can HOST a game or can JOIN(FIND) a game randomly.
The HOST player calls the function below to create a match with min/max players. This results in the "GKMatchmakerViewController" being displayed where the HOST can then select "Play Now" to find other players automatically. When all players are found and the match is created, then the "didFind match" function (below) is called.
- findMatchWithGKMatchmakerVC(minPlayers: Int, maxPlayers: Int)
- matchmakerViewController(_ viewController: GKMatchmakerViewController, didFind match: GKMatch)
The player who wants to JOIN(FIND) a match calls the following function to find a match to join. When the match is located and the match instance is provided, then the completion handler of this function is called.
GKMatchmaker.shared().findMatch(for: matchRequest, withCompletionHandler: )
After a player requests to JOIN a match, my application allows the player the option of "canceling" the match in case they want to stop waiting. If the player cancels their request, then I need to ensure the current game environment is "cleaned up" properly so if the player then decides to make another JOIN request then their request will work. I have seen when a player requests to JOIN, then cancels, then re-requests to JOIN, then the active GKMatchmakerViewController will not find the player at all. This makes me think that I did not "clean up" my previous JOIN request properly/fully.
I am performing the following to "clean up" the game environment when a player cancels their JOIN match request.
1) When the call to find a match has been made but the "matchrequest completionHandler" has not been called yet (ie: no "match" instance provided by Game Center yet), then I call the following to cancel the match request only:
GKMatchmaker.shared().cancel( )
2) Otherwise, when the "matchrequest completionHandler" was called already (meaning a "match" instance was provided by Game Center), then my application calls the following to disconnect from the match only
myMatch.disconnect( )
Question
Do I need to do anything else to properly clean up the Game Center match request in my game environment?