This error only occurs in iOS 13.3.1. It does not occur on iOS 13.3.0 or earlier.
If the app is in the foreground and it calls CXCallController.request
, it works fine. But once I background the app and execute 'CXCallController.request' (triggered by the headphone play button), I get the following error:
Error requesting transaction: Error Domain=com.apple.CallKit.error.requesttransaction Code=6 "(null)"
Code 6 is CXErrorCodeRequestTransactionError.Code.invalidAction
Here's a snippet of the sample code
let uuid = UUID()
let handle = CXHandle(type: .emailAddress, value: "[email protected]")
let startCallAction = CXStartCallAction(call: uuid, handle: handle)
let transaction = CXTransaction(action: startCallAction)
callController.request(transaction) { error in
if let error = error {
print("Error requesting transaction: \(error)")
} else {
print("Requested transaction successfully")
}
}
The same code works fine in iOS 13.3.0 and earlier regardless if the app is foreground or background. Maybe this is a 13.3.1 bug or maybe Apple implemented some security measure while apps is in the background? But I don't see it in the iOS 13.3.1 release notes.
I found a work around to my own question. It may only work to my specific condition. It may not solve the problem for all error code=6. Just so you know.
The way to fix this is that you have to be playing audio before you call CXCallController.request(:)
when your app is in the background. You can even play a silent sound for a second if you want. It doesn't have to be an audible sound.
If it doesn't work, you can try using dispatch async with a 0.1 second delay to call CXCallController.request(:)
. The idea is that you need to make sure the audio engine is active when you call CXCallController.request(:)
.