The following code outlines the steps we used to generate the live activity token:
let attributesData = try JSONSerialization.data(withJSONObject: attributesDict)
let contentStateData = try JSONSerialization.data(withJSONObject: contentStateDict)
let attributes = try JSONDecoder().decode(FlightStatusAttributes.self, from: attributesData)
let contentState = try JSONDecoder().decode(FlightStatusContentState.self, from: contentStateData)
let activity = try Activity<FlightStatusAttributes>.request(
attributes: attributes,
content: .init(
state: initialContentState,
staleDate: max(staleDate, .now.addingTimeInterval(1))
),
pushType: .token
)
Task {
for await pushToken in activity.pushTokenUpdates {
let pushTokenString = pushToken.reduce("") {
$0 + String(format: "%02x", $1)
}
LiveActivityManager.shared.addActivityToken(pushTokenString)
await LiveActivityTimeoutMainActor.shared.setTokenGenerated(value: true)
resolve(["activityId": activity.id, "token": pushTokenString])
break
}
}