How can I start live activity from server?

Generated on 8/4/2024

1 search

To start a live activity from a server, you need to follow these steps:

  1. Request a Push Token: When a live activity is started, the app requests a push token from ActivityKit. This token is unique for each live activity and is provided by the Apple Push Notifications service (APNs).

  2. Share the Push Token: The app shares this unique push token with its app server.

  3. Send Push Notification: When there is an update, the server sends a push notification to APNs with the token and the payload. APNs then delivers the payload to the respective device.

  4. Create a Channel (for Broadcast Updates): If you need to send updates to multiple devices at once, you can create a channel. The app server should send channel creation requests to APNs. The channel ID needs to be stored and shared with the app so it can subscribe to broadcast updates.

  5. Subscribe to the Channel: When the live activity is started in the app, it will request the channel ID from the remote server and subscribe to updates on that channel.

  6. Send Broadcast Push Notifications: To send updates to all devices subscribed to the channel, the server sends a single push notification to APNs with the channel ID and the payload. APNs then delivers the update to all subscribed devices.

For more detailed steps and examples, you can refer to the session Broadcast updates to your Live Activities at WWDC 2024.

Relevant Sessions

  1. Broadcast updates to your Live Activities
  2. Bring your Live Activity to Apple Watch
  3. Design Live Activities for Apple Watch