我正在尝试使用 GKMatch 对象在两个连接的玩家之间实现 VoiceChat。我的球员已经过身份验证,我还可以使用 GKMatchmakerViewController 创建比赛。
问题是当我通过委托回调收到 GKMatch 对象时matchmakerViewController:didFindMatch:
,我设置了 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) return;
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 并且在另一台设备上没有回调。我需要在其他设备上发送消息吗?关于比赛?
快速帮助将不胜感激。