【发布时间】: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