GKMatchmaker的findMatchForRequest邀请从未收到

我正在尝试邀请附近的玩家进行比赛,但邀请不是发送就是没有收到。

GKMatchMaker startBrowsingForNearbyPlayersWithHandler工作并返回相同wifi上的附近玩家,但是接着我使用findMatchForRequest并返回一个没有任何玩家的比赛,而我尝试邀请的玩家从未收到邀请通知。 这是我的代码。

我从authentication本地玩家开始:

GKLocalPlayer.localPlayer.authenticateHandler= ^(UIViewController *controller, NSError *error) { if (error) { NSLog(@"%s:: Error authenticating: %@", __PRETTY_FUNCTION__, error.localizedDescription); return; } if(controller) { // User has not yet authenticated [pViewController presentViewController:controller animated:YES completion:^(void) { [self lookForNearbyPlayers]; }]; return; } [self lookForNearbyPlayers]; }; -(void)lookForNearbyPlayers { if(!GKLocalPlayer.localPlayer.authenticated) { NSLog(@"%s:: User not authenticated", __PRETTY_FUNCTION__); return; } 

我将我的视图控制器注册为GKLocalPlayerListener的委托:

  [GKLocalPlayer.localPlayer registerListener:self]; // self is a view controller. // This works. My test local player which is a second device and appleID I setup shows up when this handler is called. [GKMatchmaker.sharedMatchmaker startBrowsingForNearbyPlayersWithHandler:^(GKPlayer *player, BOOL reachable) { NSArray * paPlayers= [NSArray arrayWithObject:player]; _pMatchRequest= [[GKMatchRequest alloc] init]; _pMatchRequest.minPlayers= 2; _pMatchRequest.maxPlayers= 4; _pMatchRequest.recipients = paPlayers; _pMatchRequest.inviteMessage = @"Join our match!"; _pMatchRequest.recipientResponseHandler = ^(GKPlayer *player, GKInviteeResponse response) { // This is never called. NSLog((response == GKInviteeResponseAccepted) ? @"Player %@ Accepted" : @"Player %@ Declined", player.alias); }; // This returns with a match without any players. [GKMatchmaker.sharedMatchmaker findMatchForRequest:_pMatchRequest withCompletionHandler:^(GKMatch *match, NSError *error) { if(error) { NSLog(@"%s:: %@", __PRETTY_FUNCTION__, error.localizedDescription); return; } else if(match != nil) { _pMatch= match; match.delegate = self; NSLog(@"players count= %lu", (unsigned long)_pMatch.players.count); // Always returns 0 } }]; } } 

我有GKLocalPlayerListener设置委托方法,但他们永远不会被调用:

 - (void)player:(GKPlayer *)player didRequestMatchWithRecipients:(NSArray<GKPlayer *> *)recipientPlayers { NSLog(@"%s", __PRETTY_FUNCTION__); } - (void)player:(GKPlayer *)player didAcceptInvite:(GKInvite *)invite { NSLog(@"%s", __PRETTY_FUNCTION__); } 

有没有人知道如何得到这个没有 GKMatchmakerViewController和iOS9的工作? 我可以find唯一的例子有不赞成的-inviteHandler方法。

这个代码在Swift中工作,如果你知道如何将它转换成Objective-C并尝试。

 GKMatchmaker.sharedMatchmaker().findMatchForRequest( request, withCompletionHandler: {(match : GKMatch!, error: NSError!) -> Void in NSLog("This works") }) 

基于在这里的多个问题,游戏中心似乎不时卡住。 在最好的情况下,它返回“游戏未识别”错误。 在最坏的情况下,它只是乐意返回到零的GC调用。 有时它会恢复自己的工作,有时候不会。 但似乎你可以通过login到iTunesConnect再次启动它,并执行以下任一操作:

  1. 添加排行榜
  2. 更改默认排行榜
  3. 添加成就

我已经添加了这个到我的debugging程序。 如果GC的某些方面停止工作,或者返回零,则在继续之前,我尝试在iTunesConnect中进行上述更改之一。 就我而言,我每周多次得到“游戏不被认可”,但其他几个人注意到“零回报值”。