Same problem here!
I'm using silent push notifications to start the Live Activities using the pushToStartTokenUpdates
from my Live Activity class, which is working nice. The issue is that I'm not able to receive the pushTokenUpdates
and send it to the backend.
- I'm registering the device
pushToStartTokenUpdates
and sending it to the backend on the application(_:didFinishLaunchingWithOptions:)
on the AppDelegate.
for await data in Activity<GiveawayWidgetAttributes>.pushToStartTokenUpdates {
let pushToStartToken = data.map { String(format: "%02x", $0) }.joined()
print("SEND PUSH TO START TOKEN TO THE BACKEND: \(pushToStartToken)")
}
}
-
I'm processing the remote notifications on the application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
-
I'm validating and analyzing the aps payload to know which kind of event it means. Start, update or end are the 3 possibilities
-
I'm starting the Live Activity by doing this:
do {
activity = try Activity<GiveawayWidgetAttributes>.request(
attributes: attributes,
content: initialContent,
pushType: .token
)
} catch {
print("ERROR: \(error.localizedDescription)")
}
Task {
for await pushToken in activity!.pushTokenUpdates {
let pushToken = pushToken.reduce("") { $0 + String(format: "%02x", $1) }
print("SEND PUSH TOKEN UPDATES: \(pushToken)")
// THIS IS NEVER CALLED
}
}
On my Info.plist:
- Supports Live Activities = TRUE
- Supports Live Activities Frequent Updates = TRUE
I can't even debug the code, because it seems that the app runs on background when receiving a silent push notification.
Possible solutions that I thought:
- Perform a background task to send the pushTokenUpdates to the backend
- Use URLSession with background configuration
Does anyone knows if this is even possible? For me it seems like a very important thing in order to use the pushToStartTokenUpdates
while using a back end to trigger the push notifications to update or end.