GKLocalPlayerListener protocol not called

As the Apple manual says; I implemented the GKLocalPlayerListener protocol in my game center class and added the local player as a listener as soon as it authenticated:

 func authenticationChanged() { if (GKLocalPlayer.localPlayer().authenticated && !self.userAutenticated) { println("Authentication changed: player authenticated.") userAutenticated = true GKLocalPlayer.localPlayer().unregisterAllListeners() GKLocalPlayer.localPlayer().registerListener(self) } else if (GKLocalPlayer.localPlayer().authenticated && self.userAutenticated) { println("Authentication changed: player not authenticated.") userAutenticated = false } } 

Protocol Execution:

 // MARK: - GKLocalPlayerListener func player(player: GKPlayer!, didAcceptInvite invite: GKInvite!) { println("Did accept invite") } func player(player: GKPlayer!, didRequestMatchWithRecipients recipientPlayers: [AnyObject]!) { println("Did request matchmaking") } 

None of the two methods that he called when I tried to invite a friend, and I also did not receive any notifications. I tried to test the game in release mode, but I have the same result. I have to say that the normal matchmaker is working correctly, I can find a player to play without problems.

EDIT:

If I test it on two devices, a notification will be received, but if I click on the notification, the application will be open and the delegate will not be called. If I close the application and restart it again, then GKLocalPlayerListener will call GKLocalPlayerListener .

What happened?

+5
source share
1 answer

I assume that when you say "normal matchmaking" that you introduced matchmakerviewcontroller:

 -(IBAction)setupMatch:(id)sender{ GKMatchmakerViewController *matchViewController = [[GKMatchmakerViewController alloc] initWithMatchRequest:matchRequest]; matchViewController.matchmakerDelegate = self; [self presentViewController:matchViewController animated:YES completion:nil];} 

Then, when players are found in matchmakerviewcontroller, FFFMMMatch will be called:

 -(void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match{ //Called when GameCenter completes the matchmaking process match.delegate = (id)self; //etc. lots of your own code here. 

didAcceptinvite is only called on the device of the recipient of the invitation after they accept the invitation:

 -(void)player:(GKPlayer *)player didAcceptInvite:(GKInvite *)invite{ //Called on the accepting device when the invitation is accepted GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithInvite:invite]; mmvc.matchmakerDelegate = self; [self presentViewController:mmvc animated:YES completion:nil]; 

}

This presents matchmakerviewcontroller to your friend. They have nothing to do, vc establishes a connection and then fires itself. Vc on the senders device is simultaneously fired.

Then didFindMatch is called on both devices and quits.

I'm not sure what didrequestMatchWithRecipients is ever called and seems redundant when didFindMatch and didAcceptInvite deal with starting the game from both ends.

I found this video from WWDC 2012 really useful: WWDC 2012 Christy Warren

+1
source

All Articles