-->

CallKit with two incoming calls

2019-07-29 19:01发布

问题:

I develop a VoIP app with CallKit.

In the case that the user receives two incoming calls and he/she accepts one of them the other one will be closed.

For example report both incoming calls:

reportInComingCall uuid: 70D506FB-6A9D-4111-8828-35DB8F330A26  
reportInComingCall uuid: 129A6D67-AC6A-480E-BCD7-ED14F7961CE5  

When the user accepts one of them I get this actions from CallKit:

perform action: CXEndCallAction uuid: 129A6D67-AC6A-480E-BCD7-ED14F7961CE5  
perform action: CXAnswerCallAction uuid: 70D506FB-6A9D-4111-8828-35DB8F330A26 

Q: Is it possible to accept one call without closing the other one?

At the end I need the following scenario: When I accept one call the other one stays on hold until I hung up the first call. CallKit shows me then the other one that I can accept it.

Ralph

回答1:

You need to set to CXProviderConfiguration that the app allows call grouping and multiple calls, like

let configuration = CXProviderConfiguration(localizedName: applicationName)
configuration.supportsVideo = supportsVideo
configuration.supportedHandleTypes = [.phoneNumber]
configuration.maximumCallGroups = 3
configuration.maximumCallsPerCallGroup = 2 /// 2 calls max per call group. Excluding host call

Also, you need to set CXCallUpdate when receiving the incoming call to tell CXProvider that the incoming call can be held/un-held and grouped

let callUpdate = CXCallUpdate()
callUpdate.supportsGrouping = true
callUpdate.supportsUngrouping = true
callUpdate.supportsHolding = true

Use that update each time you are about to report a new incoming call to CXProvider



回答2:

The system will let the user decide how to resolve the issue. Based on the choice, it will wrap up multiple actions into a CXTransaction. For example, if the user chooses to end the ongoing call, and answer the new one, the system will create a CXEndCallAction for the former and a CXStartCallAction for the latter. Both actions will be wrapped into a transaction and sent to the provider, which will process them individually. So if your app already knows how to fulfil the individual requests, there’s no further action required!

You can test it by resolving the scenario above; the list of calls will reflect your choice. The app will only process one audio session at a time. If you choose to resume a call, the other will be put on hold automatically.

For more info you can follow that tutorial