What is the correct way to programmatically accept a match invitation with GameKit's standard user interface?
I am seeing an expectedState="Invited" foundState="Active" exception
Optional(Error Domain=GKErrorDomain Code=22
"The requested operation could not be completed because the specified participant is invalid."
UserInfo={GKServerStatusCode=5097,
NSLocalizedDescription=The requested operation could not be completed because the specified participant is invalid.,
NSUnderlyingError=0x14fa2cf70 {
Error Domain=GKServerErrorDomain Code=5097 "status = 5097,
Unexpected slot state expectedState="Invited" foundState="Active"
The exception occurs under the following scenario:
Player 1 - Creates a new match with player 2
Player 1 - Makes the first move
Player 2 - Attempts to load data from the turn based match & accept the match invitation.
I am using iOs' standard user interface for match making. GKTurnBasedMatchmakerViewController
Requesting a new match
let matchRequest = GKMatchRequest()
matchRequest.minPlayers = 2
matchRequest.maxPlayers = 2
matchRequest.defaultNumberOfPlayers = 2
matchRequest.inviteMessage = "Play BoxTheDots with me"
matchRequest.recipientResponseHandler = self.matchMaker?.recipientResponse
let matchView = GKTurnBasedMatchmakerViewController(matchRequest: matchRequest)
self.presentViewController(matchView, animated: true, completion: nil)
matchView.turnBasedMatchmakerDelegate = self.matchMaker?.matchViewController
I am accepting the match invitation programmatically, which is causing and printing the error.
The code flow starts from the GKTurnBasedMatchmakerViewControllerDelegate didFindMatch method
func turnBasedMatchmakerViewController(viewController: GKTurnBasedMatchmakerViewController, didFindMatch match: GKTurnBasedMatch){
match.loadMatchDataWithCompletionHandler(self.matchDataLoaded)
match.acceptInviteWithCompletionHandler(self.acceptInvite)
}
private func acceptInvite(match:GKTurnBasedMatch?, error:NSError?){
guard error == nil else {
LogUtil.log(.CRITICAL, sub: .ERROR, o: self, method: method, msg: "could not accept match invite. \(error)")
return
}
}