Post

Replies

Boosts

Views

Activity

Reply to Get new pushToken from LiveActivity which created by push
@available(iOS 17.2, *) private static func getPushToken<Attributes>(attributes: Attributes) where Attributes : ActivityAttributes { Task{ for try await pushtoken in Activity<Attributes>.pushToStartTokenUpdates{ var templateCode = "" if attributes is ZTPreOrderAttributes{ templateCode = ZTLiveActivityTemplatedCode.preOrder.rawValue } else if attributes is ZTSkillOrderAttributes{ templateCode = ZTLiveActivityTemplatedCode.skillOrder.rawValue } let pushtokenstr = pushtoken.map { String(format: "%02x", $0) }.joined() //upload to server for create liveactivity by push uplaodToServer(pushtokenstr) } } //get new token for update Task{ for await activity in Activity<Attributes>.activityUpdates { ZTLiveActivityTool.log(" updateTokenForActivity 2") await updateTokenForActivity(activity) } } } i call this code by applaunch ,Through testing, I found that if the app is not launched, and a Live Activity is created through a push notification which wakes up the app process, the push token for the Live Activity can be retrieved in Activity.activityUpdates and uploaded to the server for subsequent push updates. However, when the app is in the background, the above code does not trigger any callbacks, and I cannot retrieve the latest push token.
2w