iosapple-push-notificationswidgetliveactivityactivitykit

Is push-to-start token for Live Activity single use?


I'm currently seeing that OS gets a new push-to-start token immediately after receiving the first notification.

Should my server immediately invalidate the push-to-start token upon usage?

Or invalidating the push-to-start token should only be done if my iOS device gets a new one and then I have to send it back to my server.


Solution

  • Apple's documentation does not say anything about the lifetime of push-to-start tokens returned by the pushToStartTokenUpdates async sequence. You should not make any assumptions about their lifetime based on currently observed behaviour; Apple could change the behaviour at any time.

    Apple describes how your app should handle obtaining push to start tokens:

    • Use the pushToStartTokenUpdates asynchronous sequence to retrieve a push-to-start token that allows you to start new Live Activities. You don’t have to start a Live Activity from your app to receive the push-to-start token.
    • Send the push-to-start token to your server and use the pushToStartTokenUpdates sequence to receive token updates. Similar to the update token, update it on your server when needed and invalidate the old token.

    You should follow the second process you suggested in your question; When you receive a new push-to-start token from the sequence, send it to your server, which should discard the old one.

    It is important to note that there are two token sequences - The static pushToStartTokenUpdates sequence on Activity and the instance-specific pushTokenUpdates sequence that provides tokens that are used to update that specific activity.

    Upon starting an activity you would always expect the activity-specific sequence to vend a new (update) token.