Live Activities Introduction and Setup – Part 2
Introduction
In Part 1 we learned about how to set up live activities from scratch. We learned about how to set up, design, and implement live activities for different modes of the iPhone including Lock Screen and Dynamic Island. We learned about the life cycle of activity from the app. How to start, update, and end an activity from the app only. But the real power of live activities comes when it works with a backend push notification when the app is in a killed state. To update users about new actions on that activity through push notifications show the real use of this api. In this part, we will learn about the live activity life cycle through push notifications.
Push Notifications for lifecycle operations
Start Activity
On devices with iOS 17.2 or newer, it’s possible to obtain the push token without starting the live activity. To do so, we need to observe the pushToStartTokenUpdates asynchronous sequence. Once we receive it and send it to the backend, it’s possible to start the live activity anytime using push notification.

Startin a activity
Update Activity
We need to send the special push token to our backend to receive live activity updates. After starting the live activity receiving this push token is feasible. The activity instance has an asynchronous sequence pushTokenUpdates, which emits the push token every time it is updated.

Update Token
Once we receive the new push token, we should send it to our backend. It’s important to note that this push token can change during the live activity’s lifecycle, so we need to keep observing the push token updates and send it every time it changes.
End Activity
Once our event ends we can easily end that particular live activity by sending an end push notification on the same update token.
Push notification payloads
It is important to understand how the whole system works. That’s why we will talk about what should be sent in the request payload to the Apple Push Notification service (APN).
Below, you can see the payload needed to start a live activity (for iOS 17.2).
- The event field has a start value.
- The content-state field should exactly match the LiveMatchScoreAttributes.
- The attributes-type field defines the type of live activity we would like to start; in our case, it’s LiveMatchScoreAttributes.
- The alert section makes the device highlight like a standard notification. It’s recommended to include it when starting the live activity to grab user attention that new live activity started.

Start activity payload
Below, you can see the payload for updating the live activity.
- The event field has an update value.
- The vital thing to note is that the timestamp has to change with each new notification. If we keep sending live activity push updates with the same timestamp, the system won’t update live activity.
- The content-state field should exactly match the LiveMatchScoreAttributes.
- There is no need to send attributes representing the static and attributes-type data.

Update Activity Payload
Finally, you can check the payload for ending the live activity here-
- The field event has an end value.
- The content-state field contains the final live activity state that will be displayed before ending by the system.The dismissal-date field defines when the system should remove the live activity. To remove the live activity immediately, the dismissal date value must be in the past. If no date is provided, it will be removed within a 4-hour window. If the provided date is more than 4 hours later, the date will be ignored, and the removal will occur after 4 hours.

End Activity Payload
Push notifications headers
To identify the push notification request as a live activity, it must include special headers, and the key headers include:
- apns-topic: This should be set to <app_bundle_id>.push-type.liveactivity.
- apns-push-type: Set this to liveactivity.
- apns-priority: This determines the priority of the push notification. To deliver it immediately, set it to 10.
- authorization: This is the authorization token for the push notification.
Testing live activity push notifications
Note: Make sure notifications are configured properly in your project and Apple certificates. Also, live activity supports Token based notifications.
All Set. We have set up everything now and we can test push notifications through any notification tester until we have our backend system ready.
Let’s look at those fields and give them the proper values:
- Device Token – This is the push token we get when observing push token updates, it was described earlier.
- bundle id – This field should be the application bundle id. (bundleid.push-type.liveactivity)
- apns-push-type – This should be set to live activity.
- apns-push-priority – This determines the priority of the push notifications, it’s better to set it to high to ensure the push notification is delivered immediately.
- payload – In this text field we should just paste the live activity push notification payload with the proper content-state value.
Now, press that send button, and let’s see the live activity update in action!
Conclusion
For supporting multiple different types of activities, animations and more are still not covered in this. There are lot more to explore. If your activity is up and running then cheers you did a great job. Happy to discuss more possibilities around it.
Source
https://developer.apple.com/documentation/activitykit/displaying-live-data-with-live-activities