我希望在呼叫者被取消并且接收方还没有应答之后停止来电通知,所以我收到用户通过另一个具有missingCall键的推包通知取消了呼叫。问题是,第一次尝试取消呼叫者的呼叫是成功的,并停止了callkit通知,但在此之后,任何呼叫都不会被取消,直到我完全终止应用程序,并且相同的事情只发生第一次成功。
这是密码
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
print("didReceiveIncomingPushWith payload")
let payloadDictionary = payload.dictionaryPayload as NSDictionary
callOption.callData = payloadDictionary.value(forKey: "aps") as! [String : Any]
let user = callOption.callData["user"] as! [String : Any]
let callerID = user["name"] as! String
let hasVideo = true
let callUpdate = CXCallUpdate()
let uuid = UUID()
callUpdate.remoteHandle = CXHandle(type: .generic, value: callerID)
callUpdate.hasVideo = hasVideo
DispatchQueue.global().async {
self.callOption.ringingApi(otherId: self.callOption.callData["snd_id"] as! String)
}
let backgroundTaskIdentifier = UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
if callOption.callData["typeCall"] as! String == "missingCall" {
self.endIncomingCall(userId: callOption.callData["snd_id"] as! String)
UIApplication.shared.endBackgroundTask(backgroundTaskIdentifier)
}
else {
self.displayIncomingCall(uuid: uuid, handle: callerID, hasVideo: hasVideo, userId: callOption.callData["snd_id"] as! String) { _ in
UIApplication.shared.endBackgroundTask(backgroundTaskIdentifier)
}
}
}这里是上面调用的函数
func displayIncomingCall(uuid: UUID, handle: String, hasVideo: Bool, userId: String, completion: ((NSError?) -> Void)? = nil) {
providerDelegate?.reportIncomingCall(uuid: uuid, handle: handle, hasVideo: hasVideo, userId: userId, completion: completion)
}
func endIncomingCall( userId: String) {
providerDelegate?.reportTheCallerEndCall( userId: userId)
}这是提供者委托
/// Use CXProvider to report the incoming call to the system
func reportIncomingCall(uuid: UUID, handle: String, hasVideo: Bool, userId: String, completion: ((NSError?) -> Void)? = nil) {
// Construct a CXCallUpdate describing the incoming call, including the caller.
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .phoneNumber, value: handle)
update.hasVideo = hasVideo
provider.reportNewIncomingCall(with: uuid, update: update) { error in
if error == nil {
let call = Call(uuid: uuid, handle: handle, userId: userId)
self.callManager.add(call: call)
}
completion?(error as NSError?)
}
}
func reportTheCallerEndCall(userId: String) {
guard let callIndex = self.callManager.findCallIndexInCallsArray(userId: userId) else { return}
provider.reportCall(with: self.callManager.calls[callIndex].uuid, endedAt: nil, reason: .unanswered)
}发布于 2022-06-23 09:21:57
我可以在您的代码中看到至少两个问题。
PushKit和CallKit框架自动处理的。pushRegistry(_:didReceiveIncomingPushWith:for:completion:)函数的completion处理程序。您可能知道,当您接收到VoIP推送时,您必须报告一个新的来电,否则系统将不会在未来向您传递任何其他VoIP推送。如果您没有在完成completion函数的过程中调用push reportNewIncomingCall处理程序,系统会认为即使您仍然这样做,也无法报告调用。self.displayIncomingCall(uuid: uuid, handle: callerID, hasVideo: hasVideo, userId: callOption.callData["snd_id"] as! String, completion: completion)删除后台任务开始/结束,并将PushKit完成传递给传入呼叫完成。
https://stackoverflow.com/questions/72726648
复制相似问题