How to merge a new call to an exciting call in CallKit

72 Views Asked by At

I have added CallKit with PushKit which works fine for the first call (Shows just Answer and Decline). I need to merge calls if another user calls while in a call, but I only get End & Accept, Decline and Hold & Accept options. Is it possible to merge calls in the same application?

private var primaryCallUUID: UUID?

func reportIncomingCallFor(handle: String, serial: String, mySerial: String, isVideo: Bool) {
    let uuid = UUID()

    let update = CXCallUpdate()
    update.supportsGrouping = true
    update.remoteHandle = CXHandle(type: .generic, value: handle)
    update.hasVideo = isVideo

    provider.reportNewIncomingCall(with: uuid, update: update) { error in
        if let error = error {
            print("Error: \(error.localizedDescription)")
        } else {
            if self.primaryCallUUID == nil {
                self.primaryCallUUID = uuid // Set the first call as primary
            } else {
                self.mergeCallsIntoGroup(with: uuid)
            }
        }
    }
}

private func mergeCallsIntoGroup(with newCallUUID: UUID) {
    guard let primaryCallUUID = self.primaryCallUUID else { return }

    let mergeCallAction = CXSetGroupCallAction(call: primaryCallUUID, callUUIDToGroupWith: newCallUUID)
    let transaction = CXTransaction(action: mergeCallAction)

    callController.request(transaction) { error in
        if let error = error {
            print("Error merging calls: \(error.localizedDescription)")
        } else {
            print("Successfully merged calls into a group")
        }
    }
}

enter image description here

We simply need to accept the incoming call without holding or ending the existing one, and the app will handle everything else seamlessly.

Any leads on this would be highly appreciated.

0

There are 0 best solutions below