Live Activity Push Token Updates getting Called Twice

I'm trying to get push tokens for Live Activities but I am getting the same token twice, Why is that?

Is there any other way to get the token just once, so I can hit the API to save the token.

Here's the code:

Task {
          for await data in runningActivity.pushTokenUpdates {
          let myToken = data.hexString
          self.count += 1
          print("Count \(self.count)\n" + myToken)
    }

Output:

Count 1 80dc21086f81.........646d7084805dc
Count 2 80dc21086f81.........646d7084805dc

I can't seem to understand why this is happening, and some times it takes significantly longer to get the tokens. Am I doing anything wrong? Please do share your thoughts.

Thank you!

Post not yet marked as solved Up vote post of cocoanautics Down vote post of cocoanautics
1.1k views

Replies

Thanks for the question. I'll answer different times first, this is because requesting a token is an async process that requires the device/processes to talk to the APNs server, you are not doing anything incorrectly here.

As for why you are getting duplicate tokens, it's not entirely clear without more logs. If you think this is a bug, feel free to file a Feedback!

A simple solution to your problem is to not have your code run if the new push token is the same as the previous one, using a local variable and a comparison should work perfectly fine