0

i am making realtime multiplayer game in cocos 2d-x for iOS. According to my flow i am doing following things with the help of this link iOS Game Center GameKit Programmatic Invite Matchmaking:

Step 1: Authenticate your player

Step 2: right after authentication set inviteHandler.

Step 3: Get your list of friend playerIds (not alias)

Step 4: Fourth, Setup your GKMatchRequest something like this... I am inviting all the friends.

Step 5: Fifth, Use the request to call findMatchForRequest:withCompletionHandler.

Step 6: Sixth, this sends the request to the other player and if they accept the "inviteHandler" from the second step gets called.

Step 7: Seventh, the "inviteHandler" from the second step gets the match for the GKInvite!

Step 8: Eighth, the "inviteeResponseHandler" from the fourth step gets called which finished the match!

Till here my code is working fine after it. 3 steps after these steps are not working can please anyone help me out ?

Step 9: Ninth, create a didChangeState from GKMatchDelegate to handle the finalization of the match.

Step 10: Send message

Step 11: Eleventh, create a didReceiveData from GKMatchDelegate.

[_match sendData:data toPlayers:_currentFriends dataMode:GKMatchSendDataUnreliable error:&error];

[_match sendData:data toPlayers:_currentFriends withDataMode:GKMatchSendDataReliable error:&error];

[_match sendDataToAllPlayers:data withDataMode:GKMatchSendDataUnreliable error:&error];

And its delegate method is:

- (void)match:(GKMatch *)match didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID {
NSLog(@"Received Data");
[_delegate match:match didReceiveData:data fromPlayer:playerID];
}

I have also tried:

- (void)match:(GKMatch *)match didReceiveData:(NSData *)data fromRemotePlayer:(GKPlayer *)player
{
    NSLog(@"received DAta");
}
Community
  • 1
  • 1
  • When you use invites the event "didChangeState" doesn't get called. Check this:- http://stackoverflow.com/questions/4337481/game-center-multiplayer-using-gkmatch-but-seems-cant-be-connected – Vizllx Jan 27 '16 at 09:05
  • @Vizllx but my data is also not receiving on other side how to solve that? – Waleed Ahmed Jan 27 '16 at 09:55

1 Answers1

0

Try This:this tutorial shows a simple application with game center

http://www.raywenderlich.com/60980/game-center-tutorial-how-to-make-a-simple-multiplayer-game-with-sprite-kit-part-1