游戏中心邀请不会显示

我一直在开发一个允许多人游戏的游戏。 我以前testing过多人邀请,他们都工作。 发送来自一个设备的请求在另一个设备上显示了一个横幅,如果邀请被接受,游戏开始。

就在提交应用之前,两天前,我再次testing了这个function,发现它已经停止工作。

- (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's application:didFinishLaunchingWithOptions: method instead of in the view controller's 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]; } }; } 

xcode中的debugging窗口显示如下:

 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; }] 

在上面的行中,“我是[…]”有意义吗?

我甚至从Ray Wenderlich的网站上下载并运行了这个教程来创build一个多人游戏,并且尝试过。 这performance出相同的问题,除非它在两个设备上运行在前台。 即使在前台运行,我的应用也不会显示邀请请求。

有没有人遇到过这个问题,或者有什么想法是怎么回事? authenticateLocalUser从applicationDidFinishLaunching调用

唯一可以进行邀请名单工作的方法是前往Settings/Notifications/Game Center ,让游戏中心显示警报 ,而不是横幅。

如果您有GC显示警报,则会显示如下所示的popup框:

在这里输入图像说明

这个对话就像一个大家长。 如果用户点击Accept ,那么你的[GKMatchmaker sharedMatchmaker].inviteHandler被调用。

如果用户点击Decline ,那么你的游戏永远不会知道他被邀请参加任何一方 。 用户击倒Decline意味着父母撕毁了邀请,从来不告诉他的孩子他被邀请参加游戏。

这是我可以邀请名人工作的唯一途径。