We're having a problem with sending invites with GKGameCenterViewController
. The view controller opens up just fine, but when we try to send an invite to somebody, it immediately fails. Both accounts have game center invites enabled and finding other players through the GKGameViewController
works fine. Here's the code we're using to manage the invites:
This method is called as soon as the GKLocalPlayer
is authenticated (authentication is called from GameViewController
, this code is in a separate Game Center managing 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 invite is received, although it it isn't called considering that the invite fails 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 pieces of code are all in the same class that conform to the GKMatchmakerViewControllerDelegate, GKGameCenterControllerDelegate, GKMatchDelegate, GKLocalPlayerListener
delegates and protocols.