Search code examples
iosiphoneapple-push-notificationscallkit

didReceiveIncomingPushWithPayload Not working when app is killed


I'm facing an issue in didReceiveIncomingPushWithPayload method as it doesn't fire when app is killed/terminated. But working perfectly when app is in background.

After investigating, I found some people recommend using the new version as this one is already deprecated

func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {

DispatchQueue.main.async(execute: {() -> Void in completion() }) }

It works good but this method is only iOS 11+ so it doesn't work for iOS 9. Any suggestions?


Solution

  • I get it like this and it works on iOS 10 and 11.

     //available(iOS, introduced: 8.0, deprecated: 11.0)
    func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, forType type: PKPushType) {
        pushRegistry(registry, didReceiveIncomingPushWith: payload, for: type) {
            // no-op
        }
    }
    
    //available(iOS 11.0, *)
    func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
    
        //your code
        completion()
    }
    

    Hope it helps.