When calling WCSession.default.transferCurrentComplicationUserInfo , the watch extension does not wake (init is never called) when the watch application is inactive.
It does work fine when the watch application is in the foreground. And the didReceiveUserInfo is being called.
WidgetKit developer mode is set, so that remainingComplicationUserInfoTransfers is not an issue.
using watchOS 9.5 and SwiftUI / WidgetKit complications.
Post
Replies
Boosts
Views
Activity
Here is the code:
let pushRegistry = PKPushRegistry(queue: .main)
func applicationDidFinishLaunching() {
pushRegistry.delegate = self
pushRegistry.desiredPushTypes = [.complication]
}
func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
let token = pushCredentials.token.reduce("") { $0 + String(format: "%02x", $1) }
print(token)
}
The watch extension has push notifications capability, and the delegate is never called with the pushCredentials.
It is received fine when the watch app is in the foreground.
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) {
print("token recieved")
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
print("push recieved")
completion()
}
}
Watch app:
import SwiftUI
@main
struct XX_Watch_App: App {
@WKApplicationDelegateAdaptor var appDelegate: XXWearableAppDelegate
private let push = PushNotificationProvider()
var body: some Scene {
WindowGroup {
AppView(...)
}
}
}
It is received fine when the watch app is in the foreground.
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 received")
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
Log("push received")
completion()
}
}
Watch app:
import SwiftUI
@main
struct XX_Watch_App: App {
@WKApplicationDelegateAdaptor var appDelegate: XXWearableAppDelegate
private let push = PushNotificationProvider()
var body: some Scene {
WindowGroup {
AppView(...)
}
}
}