Reputation: 51
I have tried many examples of starting an outgoing call on ios swift using CallKit. I have enabled VOIP in capabilities. In all cases it fails at:
callController.request(transaction) {
error in
if let error = error { print("Error requesting transaction: \(error)")}
else { print("Requested transaction successfully")
}
The error I get:
Error requesting transaction: Error Domain = com.apple.CallKit.error.request transaction Code=2 "(null)"
I can find no answer that matches Code=2.
Upvotes: 5
Views: 6153
Reputation: 12594
With an easy search, you will find all the error codes and their meaning on Apple's documentation here: https://developer.apple.com/documentation/callkit/cxerrorcoderequesttransactionerror/code
Here in the enum, code=2 means that unknownCallProvider
is the error that you are getting. The description says that "The controller couldn’t find a call provider to perform the actions in the requested transaction."
Here, it is clearly specifying that you haven't set up the provider (CXProvider
). That's why it is giving this error.
In the case of CallKit, whatever actions or transaction that you want to send to the system is done via the CXCallController
that you are using, and the system will give acknowledgment/actions via CXProvider's object(based on the configuration that you have done) and its delegate.
Now, if you haven't set the provider and its delegate, how could the system communicate to you? That's why it is giving this error.
Upvotes: 3
Reputation: 921
Where you've declared a property callController
, declare another property callProvider
of type CXProvider
. Then, make object where you keep these 2 properties to conform to CXProviderDelegate
.
Implement all the necessary functions of CXProvider
delegate. When requesting a start call action, it is necessary to fulfill the action in the delegate method, like so:
func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
/**
Configure the audio session, but do not start call audio here, since it must be done once
the audio session has been activated by the system after having its priority elevated.
*/
CallAudio.configureAudioSession()
action.fulfill()
}
Here is the code recap:
In your class:
private var provider: CXProvider!
private var callController: CXCallController!
Conform to CXProvider delegate:
class CallProvider: NSObject, CXProviderDelegate {
Create the CXProvider object and assign it's delegate:
provider = CXProvider(configuration: configuration)
provider.setDelegate(self, queue: nil) // 'nil' means it will run on main queue
Implement CXProvider delegate functions, example for start call action:
func provider(_ provider: CXProvider, perform action: CXStartCallAction) {}
Cheers!
Upvotes: -1