1

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)
    }

Console:

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!

1 Answers1

0

It's getting this call twice for me as well. To avoid additional api call I am keeping map of token and some unique id. When I get token, I compare if token is same as last one, if it is then I don't make API Call.

Post some time I remove this map as well from user defaults.

Rajesh Budhiraja
  • 192
  • 1
  • 12