iOS 13 原因:“终止应用程序,因为它在收到 PushKit VoIP 推送回调后从未向系统发送来电." [英] iOS 13 reason: 'Killing app because it never posted an incoming call to the system after receiving a PushKit VoIP push callback.'

查看:30
本文介绍了iOS 13 原因:“终止应用程序,因为它在收到 PushKit VoIP 推送回调后从未向系统发送来电."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很多天以来我一直被这个问题困扰...

From many days I am stuck at this problem...

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;
    };
}]

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

This is the payload which I am receiving and raising an incoming call as per the action

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

in CallKitManager.shared.receiveCall(model: model, delegate: self) { (initiated) incompleteOfHandlingIncomingCall(initiated)我将收到的 uuid 报告给 callkit.(通过 参考从这里)喜欢

in CallKitManager.shared.receiveCall(model: model, delegate: self) { (initiated) in completionOfHandlingIncomingCall(initiated) I reported the received uuid to callkit. (by taking ref from here) like

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 上关闭我的应用程序时,我收到一个错误

I can receive payload when app open and incoming call also initiates. But when I close my app on iOS 13, I am getting an 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 callback.'

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

As I already reported my call. If anyone having a solution it would be great.

推荐答案

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

I think that the problem is that you're reporting the call inside a DispatchQueue.main.asyncAfter. Even if you set the delay to 0, your code will run in the next run loop, i.e. not immediately. In this way the pushRegistry(_:didReceiveIncomingPushWith:for:completion:) function will end before your call has been reported and thus the system will complain.

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

这篇关于iOS 13 原因:“终止应用程序,因为它在收到 PushKit VoIP 推送回调后从未向系统发送来电."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆