Iphone GKVoiceChat无法处理GameCenter比赛
我正在尝试在我为iOS开发的游戏上设置语音聊天,它成功地创建了匹配,但是当我尝试设置语音聊天时,它什么也没做,我做错了什么?它运行时不会抛出错误。这是我用来进行语音聊天的代码Iphone GKVoiceChat无法处理GameCenter比赛,iphone,objective-c,game-center,gamekit,gkmatchmaker,Iphone,Objective C,Game Center,Gamekit,Gkmatchmaker,我正在尝试在我为iOS开发的游戏上设置语音聊天,它成功地创建了匹配,但是当我尝试设置语音聊天时,它什么也没做,我做错了什么?它运行时不会抛出错误。这是我用来进行语音聊天的代码 - (void)establishVoice { if (![GKVoiceChat isVoIPAllowed]) return; if (![self establishPlayAndRecordAudioSession]) return; NSLog(@"D
- (void)establishVoice
{
if (![GKVoiceChat isVoIPAllowed])
return;
if (![self establishPlayAndRecordAudioSession])
return;
NSLog(@"Did stablish voice chat");
chat = [match voiceChatWithName:@"GeneralChat"];
[chat start]; // stop with [chat end];
chat.active = YES; // disable mic by setting to NO
chat.volume = 1.0f; // adjust as needed.
chat.playerStateUpdateHandler = ^(NSString *playerID, GKVoiceChatPlayerState state) {
switch (state)
{
case GKVoiceChatPlayerSpeaking:
// Highlight player's picture
NSLog(@"Speaking");
break;
case GKVoiceChatPlayerSilent:
// Dim player's picture
NSLog(@"Silent");
break;
case GKVoiceChatPlayerConnected:
// Show player name/picture
NSLog(@"Voice connected");
break;
case GKVoiceChatPlayerDisconnected:
// Hide player name/picture
NSLog(@"Voice disconnected");
break;
} };
}
其中播放和录制音频会话为:
- (BOOL) establishPlayAndRecordAudioSession
{
NSLog(@"Establishing Audio Session");
NSError *error;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
if (!success)
{
NSLog(@"Error setting session category: %@", error.localizedFailureReason);
return NO;
}
else
{
success = [audioSession setActive: YES error: &error];
if (success)
{
NSLog(@"Audio session is active (play and record)");
return YES;
}
else
{
NSLog(@"Error activating audio session: %@", error.localizedFailureReason);
return NO;
}
}
return NO;
}
代码成功地记录了“Did stablish voice chat”,因此它确实运行了代码,但当我开始说话时,它似乎既没有收到声音也没有发送声音。我做错了什么?我错过什么了吗?另外,我不会让GKVoiceChatPlayerConnection启动。
确保两台设备上的wifi都已打开
(我在这上面敲了好几个小时,终于意识到我不小心在我的两台测试设备中的一台上关闭了wifi)欢迎来到Stack Overflow。如果禁用Wifi,用户可能无法创建匹配?