I am trying to create a real time multiplayer game using game center, programatically. My problem is the lack of documentation since the old inviteHandler
has been deprecated.
The first thing I do is the authentication:
- (void) authenticateLocalPlayer
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
__weak GKLocalPlayer *blockLocalPlayer = localPlayer;
localPlayer.authenticateHandler = ^(UIViewController *receivedViewController, NSError *error)
{
if (receivedViewController != nil)
{
[self presentViewController:receivedViewController animated:YES completion:nil];
}
else if (blockLocalPlayer.isAuthenticated)
{
[blockLocalPlayer registerListener:self];
}
};
}
After that, I start the invitation process as it says on apple docs.
- (void)invitePlayers:(NSArray *)friendsArray
{
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = 2;
request.maxPlayers = 2;
request.playersToInvite = friendsArray;
request.inviteMessage = @"Your Custom Invitation Message Here";
request.inviteeResponseHandler = ^(NSString *playerID, GKInviteeResponse response)
{
[self updateUIForPlayer: playerID accepted: (response == GKInviteeResponseAccepted)];
};
}
I implemented the following methods, but they are never called:
- (void)player:(GKPlayer *)player didAcceptInvite:(GKInvite *)invite
- (void)player:(GKPlayer *)player didRequestMatchWithPlayers:(NSArray *)playerIDsToInvite
How can I let the other player receive the invite and respond to it? On the apple docs the old deprecated way is demonstrated.
Try to register first for a
GKLocalPlayer
listener in order to get called via this methods:which should conforms to this protocol:
GKLocalPlayerListener