ControlPushHandler pushTokensDidChange never called

I'm trying to implement push notifications to update Control Center Widget as described here:

https://developer.apple.com/documentation/widgetkit/updating-controls-locally-and-remotely#Use-push-notifications-to-reload-controls

I've made my handler

import WidgetKit
import CommonTools
@available(iOSApplicationExtension 18.0, *)
struct ControlCenterPushHandler: ControlPushHandler {
    func pushTokensDidChange(controls: [ControlInfo]) {
        print("pushTokensDidChange called.  \(controls)")
        controls.forEach{
            print("ControlInfo \($0)")
        }
    }
}

And registered it for my controls

var body: some ControlWidgetConfiguration {
        AppIntentControlConfiguration(
            kind: WidgetConfig.Constants.controlCenterLock,
            provider: Provider()) { value in
                ControlWidgetToggle(
                    "Lock/Unlock",
                 ...
            }
            .pushHandler(ControlCenterPushHandler.self)
    }
}

and then run my software on an iPhone 15 pro running iOS 18 developer beta 7.

pushTokensDidChange is not called as I add and remove controls from the control panel. Or ever for that matter.

If I inspect push tokens when my currentValue code runs

  struct Provider: AppIntentControlValueProvider {
        func currentValue(configuration: ControlCenterButtonConfiguration) async throws -> Value {
            let controls = try await ControlCenter.shared.currentControls()
            controls.forEach{
               print("ControlInfo \($0)")
            }

pushInfo is always nil

ControlInfo ControlInfo(kind: "ControlCenterLock", pushInfo: nil, control:...

What steps are needed to get a push token?

Answered by abarsky in 807542022

Turns out I was missing the PushNotification capability on the widget extension target.

Having the same issue. Did you ever resolve it?

Accepted Answer

Turns out I was missing the PushNotification capability on the widget extension target.

Yeah! Thanks, that was my problem also.

Did you figure out how to send the notification? I am a bit confused about the documentation. it does not say what to do with the token, how to encode it or send it to the push server.

ControlPushHandler pushTokensDidChange never called
 
 
Q