BadDeviceToken Error in Live Activities

Hello everyone,

I’m currently receiving feedback from clients in a production environment who are encountering a BadDeviceToken error with Live Activities, which is preventing their states from updating. However, for other clients, the token is working fine and everything functions as expected.

I’m collaborating with the back-end developers to gather more information about this issue, but the only log message we’re seeing is:

Failed to send a push, APNS reported an error: BadDeviceToken

I would greatly appreciate it if anyone could provide some insight or information on how to resolve this issue.

Please share the apns-id of a failed push.

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
      }
    }
BadDeviceToken Error in Live Activities
 
 
Q