CallKit speaker problem

I’m developing a VoIP app that uses Linphone and CallKit. Everything works as expected until the user enables the speaker on the native CallKit screen. After that, all subsequent calls start with the speaker already on. Even if I call AVAudioSession.sharedInstance().overrideOutputAudioPort(.none), it gets overridden when the call starts (when Linphone begins playing the ringtone). I tested this behavior in WhatsApp, and it seems to work correctly there.

CallKit speaker problem
 
 
Q