使用CallKit流式传输呼叫时没有语音通信

时间:2018-12-28 17:04:46

标签: ios swift avaudiosession linphone callkit

我正尝试从分机100(Linphone App)打到102(我的应用程序)。分机102显示了来电屏幕,然后单击了接受按钮,然后,分机100开始与分机102通话,但是分机102无法听到来自100的任何消息,也分机100也无法听到来自102的消息。

我认为问题出在应用程序。但是我不知道我的应用程序有什么问题。

我在appdelegate文件中声明的这些函数是为了处理传入呼叫

let callKitManager = CallKitCallInit(uuid: UUID(), handle: "")

lazy var providerDelegate: ProviderDelegate = ProviderDelegate(callKitManager: self.callKitManager)


func displayIncomingCall(uuid: UUID, handle: String, completion: ((NSError?) -> Void)?) {
    providerDelegate.reportIncomingCall(uuid: uuid, handle: handle, completion: completion)
}

这是ProviderDelegate文件

extension ProviderDelegate: CXProviderDelegate {

func providerDidReset(_ provider: CXProvider) {
    print("Stop Audio ==STOP-AUDIO==")

    for call in callKitManager.calls {
        call.end(uuid: UUID())
    }

    callKitManager.removeAllCalls()
}

func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {

    guard let call = callKitManager.callWithUUID(uuid: action.callUUID) else {
        action.fail()
        return
    }

    configureAudioSession()

    call.answer()

    if #available(iOS 11, *) {
        print ("vKclub")
    } else {

        action.fulfill()
    }

}

func provider(_ provider: CXProvider, perform action: CXEndCallAction) {

    guard let call = callKitManager.callWithUUID(uuid: action.callUUID) else {
        action.fail()
        return
    }


    print("Stop audio ==STOP-AUDIO==")
    configureAudioSession()

    call.end(uuid: action.callUUID)

    if #available(iOS 11, *) {
        print("Our App")
    } else {
        action.fulfill()
    }


    callKitManager.remove(call: call)
}


func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
    print("Starting audio ==STARTING-AUDIO==")
}


func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
    print("Received \(#function)")
}

func configureAudioSession() {
    let session = AVAudioSession.sharedInstance()
    do {
        try? session.setCategory(AVAudioSessionCategoryPlayAndRecord)
        try? session.setMode(AVAudioSessionModeVoiceChat)
        try? session.setPreferredSampleRate(44100.0)
        try? session.setPreferredIOBufferDuration(0.005)
        try? session.setActive(true)
    } 

    }
 }

class ProviderDelegate: NSObject {

fileprivate let callKitManager: CallKitCallInit
fileprivate let provider: CXProvider

init(callKitManager: CallKitCallInit) {
    self.callKitManager = callKitManager

    provider = CXProvider(configuration: type(of: self).providerConfiguration)

    super.init()

    provider.setDelegate(self, queue: nil)

}


static var providerConfiguration: CXProviderConfiguration {
    let providerConfiguration = CXProviderConfiguration(localizedName: "vKclub")

    providerConfiguration.supportsVideo = false
    providerConfiguration.maximumCallsPerCallGroup = 1
    providerConfiguration.supportedHandleTypes = [.phoneNumber]
    return providerConfiguration
}

func reportIncomingCall(uuid: UUID, handle: String, hasVideo: Bool = false, completion: ((NSError?) -> Void)?) {

    print("This is UUID === ", uuid)
    configureAudioSession()
    let update = CXCallUpdate()
    update.remoteHandle = CXHandle(type: .phoneNumber, value: handle)
    update.hasVideo = hasVideo


    provider.reportNewIncomingCall(with: uuid, update: update) { error in


        if error == nil {
            // 3.
            self.configureAudioSession()
            let call = CallKitCallInit(uuid: uuid, handle: handle)
            self.callKitManager.add(call: call)
            lastCallUUID = uuid
            print("UUID === ", uuid)
        } else {

        }

        // 4.
        completion?(error as NSError?)
    }


}

}

0 个答案:

没有答案