We are having trouble sending invitations using the GKGameCenterViewController . The view controller opens just fine, but when we try to send an invitation to someone, it immediately fails. Both accounts have the option to enable an interactive game center, and searching for other players using GKGameViewController works great. Here is the code we use to manage invitations:
This method is called as soon as GKLocalPlayer authentication (authentication is called from GameViewController , this code is in a separate Game Center management class):
internal func authenticationChanged() { if GKLocalPlayer.localPlayer().authenticated && !authenticated { print("Authentication changed: player authenticated") authenticated = true GKLocalPlayer.localPlayer().unregisterAllListeners() GKLocalPlayer.localPlayer().registerListener(self) } else { print("Authentication changed: player not authenticated") authenticated = false GKLocalPlayer.localPlayer().unregisterAllListeners() } }
And this is the method that should be called when the invitation is received, although it is not called, given that the invitation ends in error as soon as it is sent.
public func player(player: GKPlayer, didAcceptInvite inviteToAccept: GKInvite) { //presentingViewController.dismissViewControllerAnimated(false, completion: nil) print("Accepted invite") let mmvc = GKMatchmakerViewController(invite: inviteToAccept)! mmvc.matchmakerDelegate = self presentingViewController.presentViewController(mmvc, animated: true, completion: nil) }
These two code fragments are in the same class, which correspond to the delegates and protocols GKMatchmakerViewControllerDelegate, GKGameCenterControllerDelegate, GKMatchDelegate, GKLocalPlayerListener .
source share