apple-watchpushkitapple-watch-complication

Apple Watch - PushKit complication notification is not received when the app is in background


It is received successfully when the watch app is in foreground.

Here is the code sample:

import Foundation
import PushKit

final class PushNotificationProvider: NSObject {
    let registry = PKPushRegistry(queue: nil)
    
    override init() {
        super.init()
        registry.delegate = self
        registry.desiredPushTypes = [.complication]
    }

    func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
        Log("token recieved")
    }
    
    func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
        Log("push recieved")
        completion()
    }
}

Watch app code:

import SwiftUI

@main
struct XXWearable_Watch_App: App {
    @WKApplicationDelegateAdaptor var appDelegate: XXWearableAppDelegate
    
    private let push = PushNotificationProvider()
    
    var body: some Scene {
        WindowGroup {
            AppView(...)
        }
    }
}

Solution

  • Seems to work in the background only with ClockKit and not with WidgetKit.