28

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

Pan Mluvčí
  • 1,242
  • 2
  • 21
  • 42

5 Answers5

6

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.

Lukas
  • 607
  • 4
  • 9
2

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

user1939508
  • 21
  • 1
  • 3
  • its the .voiceChat mode, changed it to .default and everything is working just fine! No idea what could cause this but what ever it is its a CallKit bug imo – Ramin Sep 10 '21 at 22:06
0

Referd from Abnormal behavior of speaker button on system provided call screen

The same issue has been experienced in the previous versions as well. So this is not the new issue happening on the call kit. This issue has to be resolved from iOS. We don't have any control over this.

Please go through the apple developer forum

CallKit/detect speaker set

and

[CALLKIT] audio session not activating?

Tom
  • 373
  • 3
  • 13
Britto Thomas
  • 2,092
  • 1
  • 15
  • 28
  • Nope. I have not frozen display like u saying. Its working but I need to double tap Speaker button to activate it and its deactivating itself. – Pan Mluvčí Mar 13 '18 at 14:59
  • I think this is not an issue of CallKit Functionality. You can restart you iPhone and then try. Sometimes iPhone does not respond properly so you can restart and then try it. – Swati Gautam Mar 14 '18 at 13:03
  • Swati: i have iph 5, 6, 6s, iphX. On all of these devices you have to push twice to see active loud speaker and its behaviour its not correct. All other buttons working OK but speaker is not doing well. – Pan Mluvčí Mar 14 '18 at 16:26
  • Please check this question https://stackoverflow.com/questions/48023629/abnormal-behavior-of-speaker-button-on-system-provided-call-screen is this kind issue what you are experiancing – Britto Thomas Mar 15 '18 at 03:15
  • 1
    Yes... there is almost same question with same problem but I cannot see any solution. – Pan Mluvčí Mar 15 '18 at 07:29
  • Please check apple forum https://forums.developer.apple.com/message/190773#190773 https://forums.developer.apple.com/message/202644#202644 – Britto Thomas Mar 16 '18 at 03:08
  • 1
    Guys.... thanks all to respond... but your links are all worthless...there are no good informations there. – Pan Mluvčí Mar 19 '18 at 13:22
0

Maybe you can setMode to AVAudioSessionModeDefault.

When I use CallKit + WebRTC

  1. I configure AVAudioSessionModeDefault mode.

  2. Alloc CXProvider and reportNewIncomingCallWithUUID

  3. Use WebRTC , after ICEConnected, WebRTC change mode to AVAudioSessionModeVoiceChat, then speaker issue happen.

  4. Later I setMode back to AVAudioSessionModeDefault, the speaker works well.

sx_bruce
  • 9
  • 1
0

I've fixed the issue by doing following steps.

  • In CXAnswerCallAction, use below code to set audiosession config.

    RTCDispatcher.dispatchAsync(on: RTCDispatcherQueueType.typeAudioSession) {
    let audioSession = RTCAudioSession.sharedInstance()
    audioSession.lockForConfiguration()
    let configuration = RTCAudioSessionConfiguration.webRTC()
    configuration.categoryOptions = [AVAudioSessionCategoryOptions.allowBluetoothA2DP,AVAudioSessionCategoryOptions.duckOthers,
                                     AVAudioSessionCategoryOptions.allowBluetooth]
    try? audioSession.setConfiguration(configuration)
    audioSession.unlockForConfiguration()}
    
  • After call connected, I'm resetting AudioSession category to default.

    func configureAudioSession() {
    let session = RTCAudioSession.sharedInstance()
    session.lockForConfiguration()
    do {            
        try session.setCategory(AVAudioSession.Category.playAndRecord.rawValue, with: .allowBluetooth)
        try session.setMode(AVAudioSession.Mode.default.rawValue)
        try session.setPreferredSampleRate(44100.0)
        try session.setPreferredIOBufferDuration(0.005)
    } 
    catch let error {
        debugPrint("Error changeing AVAudioSession category: \(error)")
    }
    session.unlockForConfiguration()}
    

Thanks to SO @Алексей Смольский for the help.

Balaji Ramakrishnan
  • 1,909
  • 11
  • 22
  • I'm having another issue when implementing this. When changing mode from voiceChat to default after call gets connected, my audio session PortOverride also gets changed. For ex, I'm calling with loudspeaker and after call gets connected, loudspeaker will changed to microphone. Any suggestions ? – Balaji Ramakrishnan Mar 01 '20 at 12:21
  • hi, where to put code configureAudioSession? You mean rtc is connected or call is connected? – famfamfam Apr 17 '20 at 08:13