【问题标题】:(GKMatch GKVoiceChat) - both Players get disconnected after didFindMatch is called(GKMatch GKVoiceChat) - 在调用 didFindMatch 后,两个玩家都会断开连接
【发布时间】:2015-06-26 13:11:09
【问题描述】:

我正在尝试使用 GKMatch 对象在两个连接的玩家之间实现 VoiceChat。 我的玩家已经过身份验证,我还可以使用 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 { if (_match != match) 返回;

switch (state) {
    case GKPlayerStateConnected:
        NSLog(@"Player connected!");
        break;
    case GKPlayerStateDisconnected:
        NSLog(@"Player disconnected!");
        _matchStarted = NO;
        break;
    case GKPlayerStateUnknown:
        NSLog(@"Player stage Unknown.");
        break;
}

}`

问题:-

我在任何一端都听不到任何音频,我错过了什么吗? 我已经尝试了 3 天了,而且(作为一个附带问题)我不确定如何处理我的第二个玩家。因为,当有比赛时,我在其中一个设备上得到了 didFindMatch 并且在另一台设备上没有回调。我需要在其他设备上发送消息吗?关于比赛?

我们将不胜感激。

【问题讨论】:

    标签: objective-c game-center gamekit gkmatchmaker


    【解决方案1】:

    听起来您是在邀请玩家而不是自动匹配玩家,如果是这种情况,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:request withCompletionHandler:^(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];
        }
    }];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-13
      • 2011-07-28
      • 1970-01-01
      • 1970-01-01
      • 2022-11-20
      • 1970-01-01
      • 2014-08-28
      • 1970-01-01
      相关资源
      最近更新 更多