[英]'NSInternalInconsistencyException', reason: 'Killing app because it never posted an incoming call to the system after receiving a PushKit VoIP push
Unable to resolve this issue tried many things.无法解决此问题尝试了很多方法。 Tried debugging but it keeps showing this error
尝试调试,但一直显示此错误
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Killing app because it never posted an incoming call to the system after receiving a PushKit VoIP push.'
*** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“正在杀死应用程序,因为它在收到 PushKit VoIP 推送后从未向系统发布传入呼叫。”
func pushRegistry(_ registry: PKPushRegistry,didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
let dict = payload.dictionaryPayload
if let handleDict = dict["handle"] as? NSDictionary {
self.callDict = handleDict
let config = CXProviderConfiguration(localizedName: "App")
config.iconTemplateImageData = UIImage(named: "user_circle")!.pngData()
config.ringtoneSound = "iphoneRingtone.mp3"
config.includesCallsInRecents = true;
config.supportsVideo = true;
let callProvider = CXProvider(configuration: config)
callProvider.setDelegate(self, queue: nil)
let callUpdate = CXCallUpdate()
let phoneNumber = CXHandle(type: .phoneNumber, value: "SoCircle")
callUpdate.remoteHandle = phoneNumber
callUpdate.hasVideo = true
let callUUID = UUID()
// Report the call to CallKit
callProvider.reportNewIncomingCall(with: callUUID, update: callUpdate, completion: { (error) in
completion()
})
}
completion()
}
There are two main reasons why you get that error.您收到该错误的主要原因有两个。
As you may know, you always have to report a new incoming call when receiving a VoIP push.您可能知道,在收到 VoIP 推送时,您总是需要报告新的来电。 If, for any reason, the value contained in
dict["handle"]
is nil
or is not an NSDictionary
, you fail to report a new incoming call and so you get the error.如果出于任何原因,
dict["handle"]
中包含的值是nil
或不是NSDictionary
,则您无法报告新的来电,因此您会收到错误消息。
The completion()
should be called only after you successfully reported a new incoming call, so inside the completion handler of reportNewIncomingCall
as you've done.只有在您成功报告了一个新的来电后,才应调用
completion()
,因此在您所做的reportNewIncomingCall
的完成处理程序中。 The problem is the completion()
that you call outside the if
.问题是您在
if
之外调用的completion()
。 Given that reportNewIncomingCall
is an asynchronous method, the completion()
outside the if
will be called before the reportNewIncomingCall
has completed, hence the system will think that you've failed to report a new incoming call.鉴于
reportNewIncomingCall
是一个异步方法,在reportNewIncomingCall
完成之前会调用if
之外的completion()
,因此系统会认为您未能报告新的来电。 So, just remove the completion()
outside the if
.因此,只需删除
if
之外的completion()
即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.