iOS 13 原因:'Killing app because it never posted an incoming call to the system after receiving a PushKit VoIP push callback.'

iOS 13 reason: 'Killing app because it never posted an incoming call to the system after receiving a PushKit VoIP push callback.'

很多天以来我都被这个问题困住了...

AnyHashable("aps"): {
    alert =     {
        action = test;
        body = "{\"action\":\"connect\",\"meetingId\":\"mdkdkkydjgedjhd\",\"from\":\"sender\",\"fromToken\":\"9d739e878521cf770d9e5136161cf7611c242ef2a8b53c83c81b6b6021a7b31b\",\"to\":\"receiver\",\"toToken\":\"e65bf5e3d6a3e440eb364fb620539de4f4c2c1bf98be5f753f5abfbe7fecea74\",\"callUUID\":\"9EB823F3-F857-490B-BCFC-373D05E56933\"}";
        title = Call;
    };
}]

这是我正在接收并根据操作发起来电的有效负载

func getPushkitPayload(payload : [AnyHashable : Any], completionOfHandlingIncomingCall : @escaping (Bool) -> Void){
    let dict : Dictionary <String, AnyObject> = payload["aps"] as! Dictionary<String, AnyObject>
    let Alert : Dictionary <String, AnyObject> = dict["alert"] as! Dictionary<String, AnyObject>
    let strBody : String = Alert["body"] as? String ?? ""

    if let data = strBody.data(using: String.Encoding.utf8) {
        do {
            let model = try JSONDecoder().decode(PushkitModel.self, from: data)
            print("RES MODEL")
            dump(model)
            //if app background
            if  UIApplication.shared.applicationState == .background || UIApplication.shared.applicationState == .inactive {
                //here check action if it is connect then show incoming call
                if model.action == "connect" {
                    CallKitManager.shared.receiveCall(model: model, delegate: self) { (initiated) in
                        completionOfHandlingIncomingCall(initiated)
                    }
                } else {
                    let sendModelToNotCenter:[String: Model] = ["Model": model]
                    NotificationCenter.default.post(name: Notification.Name("DisconnectCallFromReceiver"), object: nil, userInfo: sendModelToNotCenter)
                }
            } else {
                //here check action if it is connect then show incoming call
                if model.action == "connect" {
                    CallKitManager.shared.receiveCall(model: model, delegate: self) { (initiated) in
                        completionOfHandlingIncomingCall(initiated)
                    }
                } else {
                    let sendModelToNotCenter:[String: Model] = ["Model": model]
                    NotificationCenter.default.post(name: Notification.Name("DisconnectCallFromReceiver"), object: nil, userInfo: sendModelToNotCenter)
                }
            }
        } catch let error as NSError {
            print(error)
        }
    }
}

CallKitManager.shared.receiveCall(model: model, delegate: self) { (initiated) in completionOfHandlingIncomingCall(initiated) 我将收到的uuid报告给callkit。 (来自 taking ref from here)喜欢

public func receiveCall(model: PushkitModel, delegate : CallKitDelegate, completion : @escaping (Bool) -> ()) {
    self.delegate = delegate
    self.model = model
    receiveCallDetails(delay: 0){ (initiated) in
        completion(initiated)
    }
}

public func receiveCallDetails(delay: TimeInterval, completion : @escaping (Bool) -> ()) {
    if let model = self.model, let uuid = UUID(uuidString: model.callUUID) {
        let update = CXCallUpdate()
        update.remoteHandle = CXHandle(type: .emailAddress, value: model.from)

        let bgTaskID = UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + delay) {
            self.provider?.reportNewIncomingCall(with: uuid, update: update, completion: { (error) in
                if error == nil {
                }
                completion(true)
            })
            /* If you didn’t put caller information in your notification’s payload, call the reportCall(with:updated:) method of your app's provider object to update the calling interface. You can call that method at any time to update calls. For example, call it after your app fetches updated caller information from your VoIP server.*/
            // Asynchronously register with the telephony server and
            // process the call. Report updates to CallKit as needed.
            **self.provider?.reportCall(with: uuid, updated: update)**
            UIApplication.shared.endBackgroundTask(bgTaskID)

        }
    }  
}

当应用程序打开并且来电也启动时,我可以接收负载。但是当我在 iOS 13 关闭我的应用程序时,出现错误

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

因为我已经报告了我的电话。如果有人有解决方案那就太好了。

我认为问题在于您在 DispatchQueue.main.asyncAfter 内报告来电。即使您将延迟设置为 0,您的代码也会在下一个 运行 循环 中 运行,即不会立即。这样,pushRegistry(_:didReceiveIncomingPushWith:for:completion:) 功能将在您的呼叫被报告之前结束,因此系统会报错。

因此,请尝试删除 DispatchQueue.main.asyncAfter