问题
I am using Twilio client voice call service for calling.
Here I am facing issue in spearke ON/OFF feature.I am able to Mute/Unmute call but not able to turn On/OFF speaker. I have a same instance for both functionality. I have also checked their demo project basic phone in that this speaker ON/OFF is working and I am doing same thing in my project bur not able to do the same.
Here is my code:
if(isSpeaker == NO)
{
isSpeaker=YES;
[self.phone setSpeakerEnabled:YES];
}
else{
isSpeaker=NO;
[self.phone setSpeakerEnabled:NO];
}
self.phone is the sharedInstance of BasicPhone (their call manager class) and I am testing application in > iOS 9 both demo and my project.
回答1:
I've used this code on iOS to successfully enable/disable speakerphone. It doesn't use the Twilio device, and is somewhat specific to React Native, but the core of each function should work:
RCT_EXPORT_METHOD(setSpeakerPhoneOn) {
AVAudioSession *session = [AVAudioSession sharedInstance];
NSError *error;
[session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error];
}
RCT_EXPORT_METHOD(setSpeakerPhoneOff) {
AVAudioSession *session = [AVAudioSession sharedInstance];
NSError *error;
[session overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:&error];
}
来源:https://stackoverflow.com/questions/37893672/twilio-client-voice-call-speaker-on-off-issue