r/iOSDevelopment • u/the-name-of-the-rose • 42m ago
GameCenter invitation issues
I have a game that allows live battles. I'm hitting issues, where some invitations (between non-friends on Game Center) work, and others don't.
For the ones that don't, I get the following error:
GKInviteRecipientResponse.failed(2) — invitation could not be delivered.GKError.Code.invalidPlayer**(8)** — “The requested operation could not be completed because the player is invalid.”- Underlying
GKServerErrorDomain(5121) — “Invitation between players who have not recently played.”
Has anyone hit a similar issue (the 5121 specifically)? Ideas on how to overcome it? Here's the code:
func invite(player: GKPlayer) {
let attempt = beginMatchmaking(host: true, path: "direct_invitation", peer: player)
let callbackContext = "..."
let callbackAnalytics = "..."
let request = GKMatchRequest()
request.minPlayers = 2
request.maxPlayers = 2
request.playerGroup = 1001
request.recipients = [player]
request.recipientResponseHandler = { [weak self] _, response in
Task { [weak self] in
guard let self, self.generation == attempt else { return }
self.lastRecipientResponse = response.rawValue
self.track(.invitationResponse, ["response_code": response.rawValue])
if response == .accepted {
self.onInvitationAccepted?()
}
else {
let reason: String
switch response {
case .declined: reason = "invitation_declined"
case .failed: reason = "invitation_delivery_failed"
case .unableToConnect: reason = "invitation_unable_to_connect"
default: return
}
self.failMatchmaking(self.localizedError("connection_failed"), reason: reason)
}
}
}
GKMatchmaker.shared().findMatch(for: request) { [weak self] match, error in
Task { [weak self] in self?.receiveMatch(match, error: error, attempt: attempt, callbackContext: callbackContext, callbackAnalytics: callbackAnalytics) }
}
}
1
Upvotes