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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
回答2:
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 })
回答3:
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")
}
}