Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Callkit loudspeaker bug / how WhatsApp fixed it?

I have an app with Callkit functionality. When I press the loudspeaker button, it will flash and animate to the OFF state (sometimes the speaker is set to LOUD but the icon is still OFF). When I tap on it multiple times... it can be clearly seen that this functionality is not behaving correctly.

However, WhatsApp has at the beginning the loudspeaker turned OFF and after 3+ seconds it activates it and its working. Has anyone encountered anything similar and can give me a solution?

Youtube video link to demonstrate my problem

like image 317
Pan Mluvčí Avatar asked Mar 08 '18 09:03

Pan Mluvčí


2 Answers

There is a workaround proposed by an apple engineer which should fix callkit not activating the audio session correctly:

a workaround would be to configure your app's audio session (call configureAudioSession()) earlier in your app's lifecycle, before the -provider:performAnswerCallAction: method is invoked. For instance, you could call configureAudioSession() immediately before calling -[CXProvider reportNewIncomingCallWithUUID:update:completion:] in order to ensure that the audio session is fully configured prior to informing CallKit about the incoming call.

From: https://forums.developer.apple.com/thread/64544#189703

If this doesn't help, you probably should post an example project which reproduces your behaviour for us to be able to analyse it further.

like image 196
Lukas Avatar answered Nov 15 '22 19:11

Lukas


Above answer is correct, "VoiceChat" mode ruin everything.

Swift 4 example for WebRTC. After connection was established call next

let rtcAudioSession = RTCAudioSession.sharedInstance()
rtcAudioSession.lockForConfiguration()
do {
    try rtcAudioSession.setCategory(AVAudioSession.Category.playAndRecord.rawValue, with: 
    AVAudioSession.CategoryOptions.mixWithOthers)
    try rtcAudioSession.setMode(AVAudioSession.Mode.default.rawValue)
    try rtcAudioSession.overrideOutputAudioPort(.none)
    try rtcAudioSession.setActive(true)
} catch let error {
    debugPrint("Couldn't force audio to speaker: \(error)")
}
rtcAudioSession.unlockForConfiguration()

You can use AVAudioSession.sharedInstance() as well instead RTC

like image 30
user1939508 Avatar answered Nov 15 '22 18:11

user1939508