I am currently working on integrating an app with Siri, adding support for starting VOIP calls and sending messages. Although it is understood it is recommended to use SiriKit for calling and messaging, I would like to allow users to select a profile to use for calling. As far as I am aware the notion of selecting a profile to call from is not something SiriKit supports, therefore, it was decided to go with App Intents to allow for more control over the parameters utilized to start calls.
After integrating VOIP calling with App Intents, I noticed CallKit is not able to start calls when the App Intent is invoked from the background. I get the following error:
Error Domain=com.apple.CallKit.error.requesttransaction Code=6 "(null)”
This seems to correspond to the CXErrorCodeRequestTransactionError
invalidAction.
This error only happens when the intent is invoked from the background. Changing the App Intent property openAppWhenRun
to true solves the issue as it brings the app to foreground before running the intent.
However, I would like to support starting calls from the background to avoid making users unlock their phones prior to starting a call with Siri to make it a truly hands-free experience. I suspect the desired behavior is possible, most likely with SiriKit, as some famous VOIP calling apps (i.e. WhatsApp, Messenger, etc) exhibit the behavior I described. However, is there any way to start calls from the background with App Intents? Or is the desired behavior something exclusive to SiriKit?
I have pasted three code snippets below that can replicate the issue. At the moment I am on Xcode Version 15.3, macOS Sonoma 14.6.1, and testing on iOS 16.6.1
To demonstrate the issue I have created the following CXProviderDelegate:
class CallManager: NSObject, CXProviderDelegate {
func startCall() {
let callKitProvider = CXProvider(configuration: CXProviderConfiguration())
callKitProvider.setDelegate(self, queue: nil)
let callKitController = CXCallController()
let recipient = CXHandle(type: .generic, value: "Demo Outgoing Call")
let uuid = UUID()
let startCallAction = CXStartCallAction(call: uuid, handle: recipient)
let transaction = CXTransaction(action: startCallAction)
callKitController.request(transaction) { error in
if let error {
print(error)
} else {
print("no errors")
}
}
callKitProvider.reportOutgoingCall(with: uuid, connectedAt: nil)
}
func providerDidReset(_ provider: CXProvider) {
// no-op, not required to demonstrate the issue
}
}
Then, I have a UIViewController
that is the only screen of this example app:
class ViewController: UIViewController {
@IBOutlet weak var startCallButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
startCallButton.addTarget(self, action: #selector(buttonTapped), for: .touchUpInside)
}
@objc func buttonTapped() {
let manager = CallManager()
manager.startCall()
}
}
As for app intents, I put together a very simple intent to trigger the start of an outgoing call:
struct StartCall: AppIntent {
static var title: LocalizedStringResource = "Start Call"
static var openAppWhenRun = false
func perform() async throws -> some IntentResult {
let manager = CallManager()
manager.startCall()
return .result()
}
}
When the UIViewController is presented and I tap the button to start a call I see the green call banner appear and "no errors" is printed to the console as intended. However, when I open the Shortcuts app and run the app intent, the green banner does not appear and the message Error Domain=com.apple.CallKit.error.requesttransaction Code=6 "(null)” is printed to the console.