I'm trying to set up voice-chat on a game I'm developing for iOS, it successfully creates the match, but when I try to set up the voice-chat it does nothing, what am I doing wrong? It runs without throwing errors. Here's the code I'm using to make the voice-chat.
- (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;
} };
}
Where establishPlayAndRecordAudioSession is:
- (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;
}
The code successfully logs "Did stablish voice chat", so it does run the code, but when I start talking, it doesn't seem to get the voice nor send it. What am I doing wrong? Am I missing something? P.S. I'm not getting the GKVoiceChatPlayerConnected fired.