Game Center invitations do not appear

I am developing a game that allows multiplayer matches. I have already tested multi-user invitations and they all worked. Sending a request from one device displayed a banner on another, and if the invitation was accepted, the game began.

Just before sending the application, two nights ago, I tested this functionality again only to find that it stopped working.

- (void)authenticateLocalUser:(UIViewController *)viewController :(id<GCHelperDelegate>)theDelegate { delegate = theDelegate; self.presentingViewController = viewController; if (!gameCenterAvailable) { // Game Center is not available. userAuthenticated = FALSE; } else{ GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer]; /* The authenticateWithCompletionHandler method is like all completion handler methods and runs a block of code after completing its task. The difference with this method is that it does not release the completion handler after calling it. Whenever your application returns to the foreground after running in the background, Game Kit re-authenticates the user and calls the retained completion handler. This means the authenticateWithCompletionHandler: method only needs to be called once each time your application is launched. This is the reason the sample authenticates in the application delegate application:didFinishLaunchingWithOptions: method instead of in the view controller viewDidLoad method. Remember this call returns immediately, before the user is authenticated. This is because it uses Grand Central Dispatch to call the block asynchronously once authentication completes. */ //ios 6 [localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error) { if (viewcontroller != nil){ userAuthenticated = FALSE; [self.presentingViewController presentViewController: viewcontroller animated: YES completion:nil]; } else if (localPlayer.isAuthenticated){ // Enable Game Center Functionality userAuthenticated = TRUE; [self checkForInvite:self.presentingViewController :delegate]; if (! self.currentPlayerID || ! [self.currentPlayerID isEqualToString:localPlayer.playerID]) { // Current playerID has changed. Create/Load a game state around the new user. self.currentPlayerID = localPlayer.playerID; // get friends of local player [localPlayer loadFriendsWithCompletionHandler:^(NSArray *friends, NSError *error) { if (friends != nil) { [self loadPlayerData: friends]; } }]; } } else{ userAuthenticated = FALSE; } [scoreHandler setGameCentreAvailable:userAuthenticated]; })]; } } - (void)checkForInvite :(UIViewController *)viewController :(id<GCHelperDelegate>)theDelegate { delegate = theDelegate; self.presentingViewController = viewController; NSLog(@"Invite handler installed"); [GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite *acceptedInvite, NSArray *playersToInvite) { // Insert application-specific code here to clean up any games in progress. if (acceptedInvite){ NSLog(@"Accepted"); GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithInvite:acceptedInvite] autorelease]; mmvc.matchmakerDelegate = self; [viewController presentViewController: mmvc animated: YES completion:nil]; } else if (playersToInvite) { NSLog(@"Match Request"); GKMatchRequest *request = [[[GKMatchRequest alloc] init] autorelease]; request.minPlayers = 2; request.maxPlayers = 2; request.playersToInvite = playersToInvite; GKMatchmakerViewController *mmvc = [[[GKMatchmakerViewController alloc] initWithMatchRequest:request] autorelease]; mmvc.matchmakerDelegate = self; [viewController presentViewController: mmvc animated: YES completion:nil]; } }; } 

The debug window in xcode shows the following:

 2013-03-27 18:06:20.112 MyApp[791:907] Authentication changed: player authenticated. 2013-03-27 18:06:21.219 MyApp[791:907] Invite handler installed Mar 27 18:06:21 Neils-iPhone MyApp[791] <Notice>: 18:06:21.356712 com.apple.GameKitServices: -[GKDiscoveryManager startAdvertisingLocalPlayer:discoveryInfo:]: I am [<nil>] [7989F444CF2BDA83] discoveryInfo [{ e = 2; h = A42FD7FD; }] 

Is "I [] ..." significant in the lines above?

I even downloaded and ran a tutorial from the Ray Wenderlich website to create a multiplayer game and tried it. This shows the same problems, unless it works in the foreground on both devices. My application does not display invitations, even if it works in the foreground.

Has anyone else experienced this problem or had any ideas on what is going on? authenticateLocalUser is called from applicationDidFinishLaunching

+4
source share
1 answer

The only way I can make an invitation by name is to go to Settings/Notifications/Game Center and make the Game Center display Alerts , not banners.

If you have warnings on the GC display, you will get a popup similar to this:

enter image description here

This dialog acts like a big parent. If the user clicks Accept , then [GKMatchmaker sharedMatchmaker].inviteHandler .

If the user clicks Decline , then your game never knows that he was invited to any party . A Decline custom punch means that the parent breaks the invitation and never tells his child that he is invited to the game at all.

This is the only way to get an invitation by name to work.

+1
source

All Articles