I am designing an iOS application using PJSIP for VOIP Calling,
I start the call on speaker and on a button press i am able to make the call on normal microphone, but i am unable to make it on speaker again after pressing the speaker button.
I have used the following code to achieve that functionality :-
if sender.titleLabel?.text == "Speaker"{
do {
try audioSession.overrideOutputAudioPort(.none)
try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord)
try audioSession.setMode(AVAudioSessionModeVoiceChat)
try audioSession.setActive(true)
} catch {
print("AVAudioSession cannot be set: \(error)")
}
}else{
do {
try audioSession.overrideOutputAudioPort(.speaker)
try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord)
try audioSession.setMode(AVAudioSessionModeVoiceChat)
try audioSession.setActive(true)
} catch {
print("AVAudioSession cannot be set: \(error)")
}
}