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.'
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. If, for any reason, the value contained in
dict["handle"]isnilor is not anNSDictionary, you fail to report a new incoming call and so you get the error.The
completion()should be called only after you successfully reported a new incoming call, so inside the completion handler ofreportNewIncomingCallas you've done. The problem is thecompletion()that you call outside theif. Given thatreportNewIncomingCallis an asynchronous method, thecompletion()outside theifwill be called before thereportNewIncomingCallhas completed, hence the system will think that you've failed to report a new incoming call. So, just remove thecompletion()outside theif.