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

查看:276
本文介绍了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)
        }
    }
}

CallKitManager.shared.receiveCall中的

completeOfHandlingIncomingCall(启动)我将收到的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,您的代码也会在下一个 run循环中运行,即不会立即运行.这样, 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天全站免登陆