On my watch only app I added capabilities for Push Notifications and Background remote notifications. Then, in the App
I created an instance of my provider. I see the initializer being called, but the delegate methods are never called, so I have no device token. What am I missing?
import Foundation
import PushKit
import ClockKit
final class PushNotificationProvider: NSObject {
let registry = PKPushRegistry(queue: .main)
override init() {
super.init()
registry.delegate = self
registry.desiredPushTypes = [.complication]
}
}
extension PushNotificationProvider: PKPushRegistryDelegate {
func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
let token = pushCredentials.token.reduce("") { $0 + String(format: "%02x", $1) }
print(token)
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) async {
// Called on the main queue based on the PKPushRegistry queue parameter.
let server = CLKComplicationServer.sharedInstance()
server.activeComplications?.forEach {
server.reloadTimeline(for: $0)
}
}
}