0
votes

I'm developing a turn-based game with iOS GameCenter. I use the default GKTurnBasedMatchmakerViewController for matchmaking and invites. However after sending and accepting an invite, the player:didAcceptInvite: method is not called. I expected that this method will be called after the other player has accepted the invite from the local player.

So my questions are:

1) How do you trigger player:didAcceptInvite:?

2) How do you inform the local player if the invite was declined?

I am targeting iOS 7+ and use two real devices for testing.

The following method will be called after the local player is authenticated:

-(void)onPlayerAuthenticationChanged
{
    if ([GKLocalPlayer localPlayer].isAuthenticated)
    {
        if (!self.isLocalPlayerAuthenticated)
        {
            [[GKLocalPlayer localPlayer] registerListener:self];
            self.isLocalPlayerAuthenticated = YES;
        }
    }
    //…
}

The GC singleton conforms to the GKLocalPlayerListener protocol, which includes GKInviteEventListener and therefore player:didAcceptInvite:. My implementation looks roughly like the suggested solution in iOS 7: How to setup invitation handler for Game Center matchmaker.

1

1 Answers

1
votes

Although the documentation doesn't state this, I've learned through experimentation that didAcceptInvite only fires for real time matches. It does not fire for turn-based matches. It's unclear if this is by design (and the documentation is wrong) or it's broken. I have an open bug with Apple on this.

However, as an alternative, receivedTurnEventForMatch does fire, though, when the invited player starts playing. If there's something you need to do when the other player accepts the invite, try putting it in receivedTurnEventForMatch