My code is below and it works very well. In authenticateLocalUser add the following code:
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) { [GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite *acceptedInvite, NSArray *playersToInvite) { // Add for invite handler // Insert application-specific code here to clean up any games in progress. if (acceptedInvite) { GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithInvite:acceptedInvite] ; mmvc.matchmakerDelegate = self; // [self presentModalViewController:mmvc animated:YES]; [_delegate matchStart]; } else if (playersToInvite) { GKMatchRequest *request = [[GKMatchRequest alloc] init] ; request.minPlayers = 2; request.maxPlayers = 2; request.playersToInvite = playersToInvite; GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithMatchRequest:request] ; mmvc.matchmakerDelegate = self; // [self presentModalViewController:mmvc animated:YES]; [_delegate matchStart]; } }; [self callDelegateOnMainThread:@selector(processGameCenterAuth:) withArg:NULL error:error]; }];
idea2real
source share