Objective c (GKMatch GKVoiceChat)-在调用didFindMatch后,两名玩家都会断开连接

Objective c (GKMatch GKVoiceChat)-在调用didFindMatch后,两名玩家都会断开连接,objective-c,game-center,gamekit,gkmatchmaker,Objective C,Game Center,Gamekit,Gkmatchmaker,我正在尝试使用GKMatch对象在两个连接的玩家之间实现语音聊天。 我的玩家经过身份验证,我还可以使用GKMatchmakerViewController创建比赛 问题是,当我通过代理回调matchmakerViewController:didFindMatch:接收到GKMatch对象时,我设置了AudioSession和VoiceChat对象。但是在这个方法返回后不久,我在GKMatch的委托match:player:didChangeState: 以下是我如何在didFindMatch回调

我正在尝试使用GKMatch对象在两个连接的玩家之间实现语音聊天。 我的玩家经过身份验证,我还可以使用GKMatchmakerViewController创建比赛

问题是,当我通过代理回调
matchmakerViewController:didFindMatch:
接收到GKMatch对象时,我设置了AudioSession和VoiceChat对象。但是在这个方法返回后不久,我在GKMatch的委托
match:player:didChangeState:

以下是我如何在didFindMatch回调中创建AudioSession和VoiceChat:

- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match {

    [viewController dismissViewControllerAnimated:YES completion:nil];

    self.match = match;
    match.delegate = self;

    if (!_matchStarted && match.expectedPlayerCount == 0)
    {
        NSError *err = nil;
        AVAudioSession *audioSession = [AVAudioSession sharedInstance];
        [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&err];
        [audioSession setActive: YES error:&err];

        if (err)
        {
            NSLog(@"%@",err.localizedDescription);
        }
        self.teamChannel = [[match voiceChatWithName:@"redTeam"] retain];

        _teamChannel.volume = 1.0f;
        _teamChannel.active = YES;

        [_teamChannel start];

        _teamChannel.playerStateUpdateHandler = ^(NSString *playerID, GKVoiceChatPlayerState state) {
            switch (state)
            {
                case GKVoiceChatPlayerSpeaking:
                    NSLog(@"Speaking...");
                    break;
                case GKVoiceChatPlayerSilent:
                    break;
                    case GKVoiceChatPlayerConnected:
                    NSLog(@"Connected.");
                    break;
                    case GKVoiceChatPlayerConnecting:
                    NSLog(@"Connecting..");
                    break;
                    case GKVoiceChatPlayerDisconnected:
                    NSLog(@"Disconnected.");
                    break;
            }
        };
    }
}
我从来没有在playerStateUpdateHandler中接到过电话。我在以下函数中收到断开连接的呼叫: `-(void)match:(GKMatch*)match player:(NSString*)playerID didChangeState:(GKPlayerConnectionState)state{ 如果(_match!=match)返回

}`

问题:-

我听不到任何一端的声音,我是不是遗漏了什么? 我已经试了三天了,而且(作为一个附带问题)我不确定我的第二个球员该怎么办。例如,当有匹配时,我在其中一台设备上得到didFindMatch,而在另一台设备上没有回拨。我需要在其他设备上发送消息吗?比赛怎么样


非常感谢您的快速帮助。

如果仅在托管设备上调用了
didFindMatch
,则听起来您是在邀请玩家而不是自动匹配玩家。客户机在inviteHandler中发现了这一点

[GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite *acceptedInvite, NSArray *playersToInvite) 
{
    if (acceptedInvite)
    {
        GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithInvite:acceptedInvite];
        mmvc.matchmakerDelegate = self;

        // Do client connection stuff here
    }
    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;

        [pViewController presentViewController:mmvc animated:YES completion:nil];
    }
};
如果您正在自动匹配游戏,两名玩家都将在
[[GKMatchmaker sharedMatchmaker]findMatchForRequest:RequestWithCompletionHandler:^(GKMatch*match,NSError*error)


如果仅在托管设备上调用了
didFindMatch
,则听起来您是在邀请一个播放机,而不是自动匹配一个播放机。客户端会在InvitedHandler中发现这一点

[GKMatchmaker sharedMatchmaker].inviteHandler = ^(GKInvite *acceptedInvite, NSArray *playersToInvite) 
{
    if (acceptedInvite)
    {
        GKMatchmakerViewController *mmvc = [[GKMatchmakerViewController alloc] initWithInvite:acceptedInvite];
        mmvc.matchmakerDelegate = self;

        // Do client connection stuff here
    }
    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;

        [pViewController presentViewController:mmvc animated:YES completion:nil];
    }
};
如果您正在自动匹配游戏,两名玩家都将在
[[GKMatchmaker sharedMatchmaker]findMatchForRequest:RequestWithCompletionHandler:^(GKMatch*match,NSError*error)

 [[GKMatchmaker sharedMatchmaker] findMatchForRequest:request withCompletionHandler:^(GKMatch *match, NSError *error) 
{
    if (error != nil)
    {
        NSLog(@"MULTIPLAYER MATCH REQUEST FAILED: %@", error.localizedDescription);
    }
    else if (match != nil)
    {
        self.m_pMatchObject = [match retain];
    }
}];