how do push notifications work
Generated on 8/3/2024
1 search
Push notifications are a key feature for keeping users updated with real-time information. At WWDC 2024, Apple introduced a new way to broadcast updates for live activities to a large audience with a single push notification. Here’s a summary of how push notifications work, particularly in the context of live activities:
-
Requesting a Push Token:
- When a live activity is started, the app requests a push token from ActivityKit.
- ActivityKit receives this push token from Apple Push Notification Service (APNs) and provides it to the app.
- This push token is unique for each live activity requested by the app on the device.
- The app then shares this unique push token with its app server.
-
Sending Updates:
- When there is an update, the server sends a push notification to APNs with the token and the payload.
- APNs delivers the payload to the respective device.
- This method works well for use cases like tracking deliveries where each update is unique for every person.
-
Broadcast Push Notifications:
- For scenarios where a large number of people are actively viewing updates for the same event (e.g., sports scores), broadcast push notifications are more efficient.
- Each event is associated with a channel identified by a unique channel ID.
- The app subscribes to updates on this channel, and the server sends a single push notification to APNs with the payload.
- APNs then delivers this notification to all devices subscribed to the channel.
-
Channel Management:
- Channels are used to manage broadcast push notifications.
- The lifecycle of a channel and the live activity are independent. Even if there are no active subscribers, the channel ID remains valid.
- The server should use the channel management API to remove old or unused channels when they are no longer needed.
-
Testing and Deployment:
- The Push Notifications Console is a tool to test integration with broadcast notifications.
- For production, the server should send requests for channel management and broadcast push notifications directly to APNs using the same authentication method (certificate or token-based).
For more detailed information, you can refer to the session Broadcast updates to your Live Activities (00:01:08).