从锁定屏幕接听电话时,Callkit 和 Webrtc 没有音频 [英] Callkit and Webrtc no audio when accept call from locked screen

查看:72
本文介绍了从锁定屏幕接听电话时,Callkit 和 Webrtc 没有音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让 callkit 在来电时与 webrtc 一起工作,但是当我接到电话并从锁定屏幕接听电话时,直到我在前台模式下运行应用程序时才发出声音.我已经配置了 audiosession 向 RTCAudioSession 发送通知,但它不起作用.你有一些解决方法吗?

I'm trying to make callkit work with webrtc on incoming call, but when I receive call and accept it from locked screen there are no sound untill I run the app in the foreground mode. I've configured audiosession send notification to RTCAudioSession, but it doesn't work. Do you have some workarounds?

      func configureAudioSession() {

        let sharedSession = AVAudioSession.sharedInstance()
        do {
            try sharedSession.setCategory(AVAudioSessionCategoryPlayAndRecord, mode: AVAudioSessionModeVideoChat, options: .mixWithOthers)
            try sharedSession.setMode(AVAudioSessionModeVideoChat)
//            try sharedSession.setAggregatedIOPreference(AVAudioSessionIOType.aggregated)
        } catch {
            debugPrint("Failed to configure `AVAudioSession`")
        }
    }

    func handleIncomingCall(spaceName:String) {
        if callUUID != nil {
            oldCallUUID = callUUID
        }
        callUUID = UUID()
        print("CallManager handle uuid = \(callUUID?.description)")
        let update = CXCallUpdate()
        update.hasVideo = true
        update.remoteHandle = CXHandle(type: .generic, value: spaceName)
        self.configureAudioSession()
        provider?.reportNewIncomingCall(with: callUUID!, update: update, completion: { error in
            print("CallManager report new incoming call completion")
        })
    }

 func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
        print("CallManager didActivate")
        RTCAudioSession.sharedInstance().audioSessionDidActivate(audioSession)
        RTCAudioSession.sharedInstance().isAudioEnabled = true
        self.callDelegate?.callIsAnswered()
    }

    func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
        print("CallManager didDeactivate")
        RTCAudioSession.sharedInstance().audioSessionDidDeactivate(audioSession)
        RTCAudioSession.sharedInstance().isAudioEnabled = false
    }

推荐答案

好的,我找到了问题的原因.在 IOS 12 中,webrtc 存在问题,当您从锁定屏幕启动 webrtc 并尝试访问相机时 - 输出音量中断,因此解决方案是检查屏幕是否处于活动状态,如果不是 - 不要请求并将本地 RTCVideoTrack 添加到您的 RTCStream 中.

Okay, I've found what the cause of an issue. In IOS 12 there is a problem with webrtc, when you start webrtc from locked screen and trying to get access to camera - the output volume breaks, so the solution is to check if the screen is Active or not, and if not - do not request and add local RTCVideoTrack into your RTCStream.

这篇关于从锁定屏幕接听电话时,Callkit 和 Webrtc 没有音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆