swiftcallkitpushkit

'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.'

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()
}

Solution

  • There are two main reasons why you get that error.

    1. 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"] is nil or is not an NSDictionary, you fail to report a new incoming call and so you get the error.

    2. 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. The problem is the completion() that you call outside the if. 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. So, just remove the completion() outside the if.