Pushkit not working on iOS 15 when app is killed

523 Views Asked by At

My app was working on iOS 14 but not on iOS 15, I'm not able to receive Pushkit notifications when the app is killed. App is receiving Pushkit notifications in foreground and in background.

I also found a thread on Apple Developers forum but the prescribed solution isnt working either its here.

My code to initialise Pushkit

voipQueue = DispatchQueue(label: "mySerialqueue", attributes: [], target: nil)
//let mainQueue = DispatchQueue.main
voipRegistry = PKPushRegistry(queue: voipQueue)
voipRegistry?.delegate = self
voipRegistry?.desiredPushTypes = [.voIP]

Edit:

func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
    print("--> VOIP EVENT")
    do {
        let dict = payload.dictionaryPayload["aps"] as! NSDictionary
        let json: [String: Any] = [
            "fromName" : (dict["data"] as! NSDictionary)["fromName"] as? String ?? "",
            "toEmail" : (dict["data"] as! NSDictionary)["toEmail"] as? String ?? "",
            "fromEmail" : (dict["data"] as! NSDictionary)["fromEmail"] as? String ?? "",
            "toName" : (dict["data"] as! NSDictionary)["toName"] as? String ?? "",
            "roomId" : (dict["data"] as! NSDictionary)["roomId"] as? String ?? "",
            "user" : (dict["data"] as! NSDictionary)["user"] as? String ?? ""
        ]
        print("VOIP -->", dict)
        switch dict["name"] as! String {
        case CLIENT_CALL:
            if (UIApplication.shared.applicationState == .active) {
                if (UIApplication.shared.topViewController() as? RemoteAssistanceCallViewController) != nil {
                    print("Calling is open")
                    Utils.shared.showNotification(title: "Missed call", subtitle: "You have a missed call", body: "\(json["fromName"] ?? "Someone") tried to call you but you were busy on another call.", identifier: "\(Date())")
                    return
                } else if (CallManager.shared.isProviderActive) {
                    if (CallManager.shared.currentCall?.handle ?? "" != json["fromName"] as? String ?? "") {
                        Utils.shared.showNotification(title: "Missed call", subtitle: "You have a missed call", body: "\(json["fromName"] ?? "Someone") tried to call you but you were busy on another call.", identifier: "\(Date())")
                    }
                    return
                }
                completion()
            }
            newCallEvent(data: CallRequestModel(JSON: json)!)
            PusherHelper.shared.setupPusher()
            break

        default:
            if (UIApplication.shared.applicationState == .active || CallManager.shared.isProviderActive) {
                return
            }
            CallManager.shared.callInVein()
            print("Call Unknown! name. Alas!")
            completion()
        }
    } catch let error as NSError {
        print(error)
    }
    
    if (!PusherHelper.shared.isConnected) {
        PusherHelper.shared.setupPusher()
    }
    
}



func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
    print(pushCredentials.token)
    let deviceToken = pushCredentials.token.map { String(format: "%02x", $0)}.joined()
    print("push reistry --> device token: \(deviceToken)")
    NotificationsHelper.shared.updateVoIPToken(voIPToken: deviceToken)
}
0

There are 0 best solutions below