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:
-
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).
-
Share the Push Token: The app shares this unique push token with its app server.
-
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.
-
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.
-
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.
-
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
Broadcast updates to your Live Activities
With broadcast push notifications, your app can send updates to thousands of Live Activities with a single request. We’ll discover how broadcast push notifications work between an app, a server, and the Apple Push Notification service, then we’ll walk through best practices for this capability and how to implement it.
Bring your Live Activity to Apple Watch
Bring Live Activities into the Smart Stack on Apple Watch with iOS 18 and watchOS 11. We’ll cover how Live Activities are presented on Apple Watch, as well as how you can enhance their presentation for the Smart Stack. We’ll also explore additional considerations to ensure Live Activities on Apple Watch always present up-to-date information.
Design Live Activities for Apple Watch
Starting in watchOS 11, Live Activities from your iOS app will automatically appear in the Smart Stack on a connected Apple Watch. Learn how to optimize the layout of your Live Activity for the wrist, and provide the right level of information and interactivity at the right time.