GKVoiceChat not working

I am trying to implement GKVoiceChat between two iPhones (an iPhone X and an iPhone 5s) in iOS11.3.1 Xcode 9.3.1. I have the GameKit connection working fine but not the voice. Has anyone got VoiceChat working? Can anyone see anything wrong in the code here? Thanks...


Here is my relevant code:

#import <GameKit/GameKit.h>
#include <AVFoundation/AVFoundation.h>


//in a method at the beginning......
    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    NSError *error= nil;
    [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
    [audioSession setActive:YES error:&error];
    if(error){
        NSLog(@"audioSession: %@ %ld %@", [error domain], (long)[error code], [[error userInfo] description]);
    }else{
        [audioSession overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error];
        if(error){
            NSLog(@"audioSession1: %@ %ld %@", [error domain], (long)[error code], [[error userInfo] description]);
        }else{
            if( [GKVoiceChat isVoIPAllowed]){
                allChannel=[[GKVoiceChat alloc] init];
                allChannel=[myMatch voiceChatWithName:@"allPlayers"];
                if(allChannel){
                    allChannel.volume = 1.0;
                    allChannel.active=YES;
                    [self performSelector:@selector(delayedStart) withObject:nil afterDelay:6.0f];//give Game Center a chance to respond
                }else{
                    NSLog(@"no channel was oppend");
                }
            }else{
                NSLog(@"voip not allowed");
            }
        }
    }


-(void)delayedStart{
    [allChannel start];
    NSLog(@"started");
}


Here are the errors I get that I don't think are relevant. They all occur before the delayed call to [allChannel start] and they are there whether or not I implement any of the GKVoiceChat code. I think they are bugs in the GKMatch system. I am ignoring them:


//these errors occur before the match has been found and before the code above is executed:

2018-05-17 21:05:31.006119-0400 Go[477:67899] [log]  [ERROR] gckSessionCheckPendingConnections:1438 gckSessionCheckPendingConnections: iICEChecksLeft=0, iUnconnectedNodeCount=0, iDDsExpected=1
2018-05-17 21:05:31.063331-0400 Go[477:67847] [log]  [ERROR] ICEStopConnectivityCheck:2688 ICEStopConnectivityCheck() found no ICE check with call id (2019854734)
2018-05-17 21:05:31.065208-0400 Go[477:67847] [log]  [ERROR] gckSessionCheckPendingConnections:1438 gckSessionCheckPendingConnections: iICEChecksLeft=0, iUnconnectedNodeCount=0, iDD

//  the next line occurs when there is a call to matchmakerViewController:viewControllerDidFindMatch: and the code above is then executed

2018-05-17 21:05:35.251683-0400 Go[477:67566] [Error] Extension request cancelled with error: Error Domain=NSExtensionErrorDomain Code=-2 "Extension cancelled by host." UserInfo={NSLocalizedDescription=Extension cancelled by host.}


Here are the errors I get after setting the GKVoiceChat object to start (i.e. after that 6 second delay):

2018-05-17 21:05:40.766056-0400 Go[477:67566] started
2018-05-17 21:05:41.310557-0400 Go[477:67895] [log]  [ERROR] openLogDump:65 failed to open /var/mobile/Library/Caches/com.apple.VideoConference/logs/20180517-210541-0757771790-CallSettings.calldump with error 1
2018-05-17 21:05:41.449639-0400 Go[477:68033] [] WiFi:[548298341.448992]: Missing com.apple.wifi.manager-access entitlement
2018-05-17 21:05:41.449986-0400 Go[477:68033] [] WiFi:[548298341.449970]: Missing com.apple.wifi.manager-access entitlement
2018-05-17 21:05:41.450418-0400 Go[477:68033] [] WiFi:[548298341.450400]: Missing com.apple.wifi.manager-access entitlement
2018-05-17 21:05:41.451010-0400 Go[477:68033] [] WiFi:[548298341.450924]: Missing com.apple.wifi.manager-access entitlement
2018-05-17 21:05:41.451625-0400 Go[477:68033] [] WiFi:[548298341.451608]: Missing com.apple.wifi.manager-access entitlement
2018-05-17 21:05:43.648429-0400 Go[477:67566] Bad response from apsd: Connection interrupted
2018-05-17 21:05:43.662956-0400 Go[477:67566] [Warning] Remote loader crashed for request: <NSMutableURLRequest: 0x10ba1bb60> { URL: http://init.ess.apple.com/WebObjects/VCInit.woa/wa/getBag?ix=4 }
2018-05-17 21:05:43.664051-0400 Go[477:67566] [Warning]  => Retrying... (0/5) retries
2018-05-17 21:05:43.667507-0400 Go[477:67566] [Warning] Remote loader crashed for request: <NSMutableURLRequest: 0x10ba1bb60> { URL: http://init.ess.apple.com/WebObjects/VCInit.woa/wa/getBag?ix=4 }
2018-05-17 21:05:43.667646-0400 Go[477:67566] [Warning]  => Retrying... (1/5) retries
2018-05-17 21:05:45.845023-0400 Go[477:67566] [Warning] Remote loader crashed for request: <NSMutableURLRequest: 0x10ba1bb60> { URL: http://init.ess.apple.com/WebObjects/VCInit.woa/wa/getBag?ix=4 }
2018-05-17 21:05:45.845205-0400 Go[477:67566] [Warning]  => Retrying... (2/5) retries
2018-05-17 21:05:46.484616-0400 Go[477:67895] [log] VideoConference [ERROR] -[VideoConference inviteDataForParticipantID:callID:remoteInviteData:nonCellularCandidateTimeout:error:]:855 VideoConference: CALLID MISMATCH 0x10bb332e0 client callID 6161504380 internal callID 0
2018-05-17 21:05:46.490559-0400 Go[477:68030] [log]  [ERROR] VCAudioReceiver_DiscardQueueExcess:454 AudioReceiver is NULL
2018-05-17 21:05:46.490986-0400 Go[477:68030] [log]  [ERROR] VCAudioReceiver_DiscardQueueExcess:454 AudioReceiver is NULL
2018-05-17 21:05:50.246310-0400 Go[477:67566] [Warning] Remote loader crashed for request: <NSMutableURLRequest: 0x10ba1bb60> { URL: http://init.ess.apple.com/WebObjects/VCInit.woa/wa/getBag?ix=4 }
2018-05-17 21:05:50.246469-0400 Go[477:67566] [Warning]  => Retrying... (3/5) retries
2018-05-17 21:05:52.019693-0400 Go[477:67895] [log] VCCallSession [ERROR] -[VCCallSession startConnectionWithParticipantID:callID:usingInviteData:isCaller:capabilities:idsSocket:destination:error:]_block_invoke:2215 - Reporting not available (no backends)
2018-05-17 21:05:56.819849-0400 Go[477:67566] [Warning] Remote loader crashed for request: <NSMutableURLRequest: 0x10ba1bb60> { URL: http://init.ess.apple.com/WebObjects/VCInit.woa/wa/getBag?ix=4 }
2018-05-17 21:05:56.820068-0400 Go[477:67566] [Warning]  => Retrying... (4/5) retries
Answered by PBK in 312245022

And the answer is....


[allChannel start]; must come before


allChannel.volume = 1.0;

allChannel.active=YES;


Thank you for listening....... [allChannel stop];

Actually, that last error in the first box above does only occur if I implement the GKVoiceChat code but before the [allChannel start];


2018-05-17 21:05:35.251683-0400 Go[477:67566] [Error] Extension request cancelled with error: Error Domain=NSExtensionErrorDomain Code=-2 "Extension cancelled by host." UserInfo={NSLocalizedDescription=Extension cancelled by host.} 

and if only one device tries to make a GKVocieChat connection I only get this error:

2018-05-17 22:08:43.923117-0400 Go[562:92959] [log]  [ERROR] VCAudioReceiver_DiscardQueueExcess:454 AudioReceiver is NULL
Accepted Answer

And the answer is....


[allChannel start]; must come before


allChannel.volume = 1.0;

allChannel.active=YES;


Thank you for listening....... [allChannel stop];

I placed

voiceChannel!.start()

above

voiceChannel!.isActive = true

and I'm still getting the same errors you described before. Is this the only change you made?

I will have to check that app and get back to you in a few days.

Okay! I appreciate it.

I can't get this code running in Xcode right now to see if it sends out any warnings. As an app on the app store (Go Game Connect) it seems to be working.


Here is the relevant code:


   

    //global variables:
    GKVoiceChat *allChannel;
    GKMatch *myMatch;
    
    
    //from within
-(void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)match
    //.....
    if(!myMatch){
        self->myMatch=match;
        self->myMatch.delegate = self;
        [self performSelector:@selector(voiceChatStuff) withObject:nil afterDelay:1.0f];
    }else{
        self->myMatch=match;
        self->myMatch.delegate = self;
        [self voiceChatStuff];
    }
    //......
}
        
    
-(void)voiceChatStuff{
    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    NSError *error= nil;
    [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord mode:AVAudioSessionModeVoiceChat options:AVAudioSessionCategoryOptionDefaultToSpeaker error:&error];
    [audioSession setActive:YES error:&error];
    if(!error && [GKVoiceChat isVoIPAllowed]){
        allChannel=[[GKVoiceChat alloc] init];
        allChannel=[myMatch voiceChatWithName:@"allPlayers"];
        if(allChannel){
            [allChannel start];
            allChannel.volume = 0.8;
            allChannel.active=YES;
        }
    }
}
        
//to disconnect from voice chat:
    allChannel.active=NO;
    [allChannel stop];
    
    
   

Thank you so much! I downloaded your game "Go Game Connect" on both devices and tried playing it several times but there was never any audio coming through. Volume was all the way up. Speakers and microphone are working. Connected to wifi with good bandwidth.

I even tried it with someone else I know who has a different model phone, but it didn't work.

I got the same outcome when I tried running my own game.

Is the audio working for your devices when you play "Go Game Connect"?

Belatedly - yes it is. There is a settings in Settings under Privacy that allows the app to access microphone. Perhaps yours is set to 'no'.

Hello again!

Thank you for the suggestion! I downloaded your app back when we were talking about this in 2019 and it was not working. I definitely checked the microphone settings for your app and mine and that was not the issue.

I researched all of the info I could find online, got someone on codementor.io to try and help, tried everything I could imagine and was getting some weird errors and got stuck, so I just submitted a TSI to Apple in September 2019. After some back and forth and sending them my XCode project, one of the engineers told me this:


“it looks like the problem is with GKVoiceChat and not the audio side. I actually spent most of the afternoon on this Friday, but wasn’t able to come up with a clean summary…In any case, unfortunately, it looks like the underlying problem here a problem on our side…I’m still seeing failures from the audio internals of GKVoiceChat. If you haven’t already, please file a bug at:

<https://feedbackassistant.apple.com>

…and send me the number once it’s filed. Once the bug is filed I’ll reach out the the GameCenter team and see if they can shed any light on what might be going on and if you have any options for getting things working.”


So I filed the “feedbackassistant” report as I was asked to do, and over a month later I got this from the same engineer:

“I don’t have any new information I can share. I’ve been told that it’s a bug

but can’t provide any information beyond that...Unfortunately, that’s really all I can say.”


And so I started looking into paid options like Agora.io and making a facetime audio call from my app…

Until today.


Today I simply ran the *same* app that I had made before (which was Not working in September 2019), and without changing *any* code whatsoever, it works just fine now. The audio comes through on both devices.

So there you go. I hope that helps. I am super excited to get to use this now!! I hope you guys are too.

I have tried VoiceChat on the apps.

VioceChat does not work if the two devices are connected to Game Center through Cellular Data.

VoiceChat does work if the two devices are connected through Game Center using the same WiFi.

I did not test connecting two devices to Game Center using two different WiFi links.

Were you able to get VoiceChat to work using Cellular Data?

I have faced exactly the same problem. Interestingly enough, voice chat works well on my iPhone and iPad Pro running iOS 14, but not on my old iPad running iOS 12.4.9. I get exactly the same errors as in the previous posts. Access to mic is enabled in Settings, voice chat is initiated but no sound.
I have another issue with GameCenter voice chat on my son's iPad. But there, initiating voice chat with name after finding a game results in a nil GKVoiceChat object and I do not even see permission to access mic for my application. I wonder if this could be caused by some parental restrictions.
Please advise if you have solved the problem. Thanks!
GKVoiceChat not working
 
 
Q