This is not a give-me-code question, this is a feasibility question. If I initiate a phone call using CallKit, is it also possible to programmatically end it?
Asked
Active
Viewed 1.1k times
3 Answers
12
Yes, we can do programmatically, but we have to keep the UUID for that call,
CXEndCallAction *endaction = [[CXEndCallAction alloc] initWithCallUUID:callUUID];
[cxcallcontrollerobject requestTransaction:[CXTransaction transactionWithActions:@[action]] completion:completion];
+ (CXTransaction *)transactionWithActions:(NSArray <CXAction *> *)actions {
CXTransaction *transcation = [[CXTransaction alloc] init];
for (CXAction *action in actions) {
[transcation addAction:action];
}
return transcation;
}
Hope this helps.

RJV Kumar
- 2,408
- 1
- 19
- 28
-
1I am getting error code 4 , it means invalid UUID. i am passing same UUID which i have used while establish call. – Saurabh Prajapati Jan 13 '17 at 12:51
-
how the uuid has been stored? NSUserDefaults or some other way. Did you convert that into integer?(just for clarification) – RJV Kumar Jan 16 '17 at 05:25
-
No i am taking it as global variable in appDelegate – Saurabh Prajapati Jan 16 '17 at 08:48
-
if you are generating the uuid, check the uuid is generated or not. Even we faced the uuid becomes nil sometimes. – RJV Kumar Jan 16 '17 at 09:36
-
1I have checked that UUID is not nil & is generated Successfully. – Saurabh Prajapati Jan 17 '17 at 05:47
-
@RJVKumar what is "callUUID".. From where i get callUUID ? – Varinder Singh iPhone Dev Jul 26 '17 at 10:11
-
@VarinderSingh UUID is the identifier for that particular call. You can get when you are initiating the call. – RJV Kumar Jul 26 '17 at 12:32
-
1Error Getting. No known class method for selector 'transactionWithActions' – Varinder Singh iPhone Dev Aug 10 '17 at 11:32
-
@VarinderSingh + (CXTransaction *)transactionWithActions:(NSArray
*)actions { CXTransaction *transcation = [[CXTransaction alloc] init]; for (CXAction *action in actions) { [transcation addAction:action]; } return transcation; } – RJV Kumar Aug 11 '17 at 06:10 -
@RJVKumar Do you know what I need to import to get rid of those two errors?: "Use of undeclared identifier 'cxcallcontrollerobject'" and "Use of undeclared identifier 'transactionWithActions'" – gignu Aug 04 '21 at 17:54
7
Close All Call (Swift4)
func endCall(call: UUID) {
let endCallAction = CXEndCallAction(call: call)
let transaction = CXTransaction(action: endCallAction)
cxCallController.request(transaction) { error in
if let error = error {
print("EndCallAction transaction request failed: \(error.localizedDescription).")
self.cxCallProvider.reportCall(with: call, endedAt: Date(), reason: .remoteEnded)
return
}
print("EndCallAction transaction request successful")
}
}

Mohammad Razipour
- 3,643
- 3
- 29
- 49
-
1Hey the reportCall method doesn't seem to dismiss the CallKit UI, it worked for you? – vivek takrani Sep 03 '18 at 10:08
-
1@vivektakrani guard let uuid = UUID(uuidString: "CallId") else { return } self.cxCallProvider.reportCall(with: uuid, endedAt: Date(), reason: .remoteEnded) – Mohammad Razipour Sep 04 '18 at 09:05
-
1Note: without the reportCall method the status bar's color's change might have an unintented delay. – jason d May 18 '22 at 13:14
4
In swift use the following code, uuidCallKit is the UUID of the current call that I'm having with me.
let controller = CXCallController()
let transaction = CXTransaction(action:
CXEndCallAction(call: uuidCallKit))controller.request(transaction,completion: { error in })

ak_ninan
- 721
- 7
- 15