1

I developed an iPhone App that uses the GameCenter. To support different levels of my game I set the playerGroup within the GKMatchRequest class. If the match is started by an automatic match making process both users knows the playerGroup, but if the invitation process is used, the invitee does not know the playerGroup.

I tried to read the playerGroup within the method

-   (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match

by using

[viewController matchRequest].playerGroup, but the property playerGroup always return 0, instead the right player group.

Does anyone have an idea how to solve this problem. I need to know the playerGroup to load the right level.

Thank you very much for your help

DShah
  • 9,768
  • 11
  • 71
  • 127
Ludi
  • 11
  • 1

3 Answers3

1

I stumpled upon the same problem. As a workaround I am sending a handshake with all relevant game customization info through the GKMatch object. I send the data with GKMatchSendDataReliable DataMode so the handshake doesn't fail.

After all information is collected by the clients the actual game logic is created and started on its basis.

1

As far as I know, this is a built in limitation of Game Center. I have been struggling with it too, and asked on several forums, including Apples devforums, without any response. I've written a bug report to Apple and I suggest you do the same.

As a workaround in my own game, where I have several different rulesets that players choose from and where players have to share the same rules for multiplayer matches to work, I put in a "double check" after the game actually starts to make sure everyone is on the same rules: Just in case someone was invited and is using the wrong rules.

What I did is, as soon as the game starts (which you should detect for in both the didFindMatch method of the GKMatchMakerViewControllerDelegate and in match:player:didChangeState: in GKMatchDelegate) I let the players enter the game and then send out packages containing the rules they use to all the other players. When they receive this data, they match it with their own rules and if anyone is using the wrong rules, the game will put up an alert and disconnect the match.

It's a bit ugly, and it's very clear that Apple ought to implement a way to set a GKMatchRequest for a GKMatchMakerViewController when initialized by an invite. But at least it works.

0

You can check the Player Group of a match request like this.

func player(player: GKPlayer, didAcceptInvite inviteToAccept: GKInvite)    {
    if inviteToAccept.playerGroup == 0 || inviteToAccept.playerGroup == myPlayerGroup  {
        inviteAccepted()
    }
    else {
        // TO SOMETHING
        myPlayerGroup = inviteToAccept.playerGroup
        inviteAccepted()
    }
123FLO321
  • 854
  • 1
  • 7
  • 20