From 25dd82a4da4e0db505c8e99850ad89e9bc4e9bec Mon Sep 17 00:00:00 2001 From: Christophe Deschamps Date: Tue, 15 Oct 2024 09:27:14 +0200 Subject: [PATCH] - Clone address in startCall to avoid potential crash with c pointer beeing unrefed. - Do not force unwrap of incoming call that could be nil --- Classes/Swift/CallManager.swift | 3 +-- Classes/Swift/ProviderDelegate.swift | 34 +++++++++++++++------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Classes/Swift/CallManager.swift b/Classes/Swift/CallManager.swift index 531efc31a..b63a9f158 100644 --- a/Classes/Swift/CallManager.swift +++ b/Classes/Swift/CallManager.swift @@ -271,12 +271,11 @@ import AVFoundation // for outgoing call. There is not yet callId @objc func startCall(addr: OpaquePointer?, isSas: Bool, isVideo: Bool, isConference: Bool = false) { - if (addr == nil) { + guard addr != nil, let sAddr = Address.getSwiftObject(cObject: addr!).clone() else { Log.i("Can not start a call with null address!") return } - let sAddr = Address.getSwiftObject(cObject: addr!) if (CallManager.callKitEnabled() && !CallManager.instance().nextCallIsTransfer && lc?.conference?.isIn != true) { let uuid = UUID() let name = FastAddressBook.displayName(for: addr) ?? "unknow" diff --git a/Classes/Swift/ProviderDelegate.swift b/Classes/Swift/ProviderDelegate.swift index f294c0479..1da499609 100644 --- a/Classes/Swift/ProviderDelegate.swift +++ b/Classes/Swift/ProviderDelegate.swift @@ -209,23 +209,25 @@ extension ProviderDelegate: CXProviderDelegate { let callId = callInfo?.callId Log.directLog(BCTBX_LOG_MESSAGE, text: "CallKit: answer call with call-id: \(String(describing: callId)) and UUID: \(uuid.description).") - let call = CallManager.instance().callByCallId(callId: callId) - - if (UIApplication.shared.applicationState != .active) { - CallManager.instance().backgroundContextCall = call - CallManager.instance().backgroundContextCameraIsEnabled = call?.params?.videoEnabled == true || call?.callLog?.wasConference() == true - /*if #available(iOS 16.0, *) { - if (call?.cameraEnabled == true) { - call?.cameraEnabled = AVCaptureSession().isMultitaskingCameraAccessSupported - } - } else { - call?.cameraEnabled = false // Disable camera while app is not on foreground - }*/ + if let call = CallManager.instance().callByCallId(callId: callId) { + if (UIApplication.shared.applicationState != .active) { + CallManager.instance().backgroundContextCall = call + CallManager.instance().backgroundContextCameraIsEnabled = call.params?.videoEnabled == true || call.callLog?.wasConference() == true + /*if #available(iOS 16.0, *) { + if (call?.cameraEnabled == true) { + call?.cameraEnabled = AVCaptureSession().isMultitaskingCameraAccessSupported + } + } else { + call?.cameraEnabled = false // Disable camera while app is not on foreground + }*/ + } + CallManager.instance().callkitAudioSessionActivated = false + CallManager.instance().lc?.configureAudioSession() + CallManager.instance().acceptCall(call: call, hasVideo: call.params?.videoEnabled ?? false) + action.fulfill() + } else { + endCall(uuid: uuid) } - CallManager.instance().callkitAudioSessionActivated = false - CallManager.instance().lc?.configureAudioSession() - CallManager.instance().acceptCall(call: call!, hasVideo: call!.params?.videoEnabled ?? false) - action.fulfill() } func provider(_ provider: CXProvider, perform action: CXSetHeldCallAction) {