1

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
    }
}

Player 1 after making the first turn enter image description here

Player 2 before loading match from player 1 enter image description here

sdc
  • 2,603
  • 1
  • 27
  • 40

1 Answers1

0

I answered a question about entirely-programmatically-handled turn-based matches here, and even though the question on this page is about using the standard GKTurnBasedMatchMakerViewController, I belive the information in that post could be helpful.

What one wants, of course, is a simple delegate function named localPlayerDidAcceptInvitation(...). But absent that, the information available at that link might be helpful in kludging together something that works.

Community
  • 1
  • 1
Le Mot Juiced
  • 3,761
  • 1
  • 26
  • 46