Contents

Sending broadcast push notification requests to APNs

Transmit your broadcast notification payload to Apple Push Notifications service (APNs).

Overview

Starting with iOS 18 and iPadOS 18, devices can subscribe on channels to receive updates for Live Activities. You can send a single push notification to APNs on the channel to update a Live Activity event to a large audience. When you have a notification to send on a channel, your provider must construct a POST request and send it to APNs. Upon receiving your server’s POST request, APNs validates the request using either the provided authentication token or your server’s certificate. If authentication succeeds, APNs then validates the channel ID you’re using to send the push notification. After channel validation, APNs tries to send your JSON payload to all the devices subscribed to the channel. For information on sending test notifications without setting up the environment, refer to Testing notifications using the Push Notification Console.

As a best-effort service, APNs may reorder notifications you send on the same channel. If APNs can’t deliver a notification immediately, it may store the notification based on the channel’s message storage policy specified during channel creation. Notifications with Medium and Low apns-priority might get grouped and delivered in bursts to the person’s device. APNs may also throttle your notifications and, in some cases, not deliver them. The exact behavior is determined by the way the person interacts with your application and the power state of the device.

Establish a connection to APNs

Use HTTP/2 and TLS 1.2 or later to establish a connection between your provider server and one of the following servers:

For more details on establishing a connection to the APNs server to send requests, refer to Establishing a connection to Apple Push Notification service (APNs).

Send a POST request to APNs

Include header fields in your notifications or the system won’t be able to deliver them. In addition to the preceding data, add the following header fields in to your request. Other headers are optional or may depend on whether you’re using token-based or certificate-based authentication.

Header field

Required

Description

:method

Required

The value POST.

:path

Required

The value of this header is /4/broadcasts/apps/<bundle ID>.

authorization

Required for token-based authentication.

The value of this header is bearer provider_token, where the provider_token is the encrypted token that authorizes you to send notifications for the specified topic. APNs ignores this header if you use certificate-based authentication. For more information, refer to Establishing A Certificate Based Connection To Apns

apns-request-id

Optional

An optional custom request identifier that’s returned back in the response. The request identifier must be encoded as a UUID string.

apns-channel-id

Required

The channel ID is a base64-encoded string that identifies the channel to publish the payload. The channel ID is generated by sending channel creation request to APNs. For more information, refer to Sending Channel Management Requests To Apns.

apns-expiration

Required

The date when the notification expires. This value represents a UNIX epoch expressed in seconds (UTC). If the value is nonzero, APNs stores the notification and attempts delivery at least once, repeating as necessary until the specified date. If the value is 0, APNs attempts to deliver the notification only once and doesn’t store it. Providing a nonzero expiration for a channel created with the No Message Stored storage policy results in message rejection. [Image] A single APNs attempt may involve retries over multiple network interfaces and connections of the destination device. These retries often span some time period, depending on network characteristics. Additionally, a push notification may take some time on the network after APNs sends it to the device. APNs makes best efforts to honor the expiry date without any guarantee. If the value is nonzero, the notification may deliver after the specified timestamp. If the value is 0, the notification may deliver with some delay.

apns-priority

Required

The priority of the notification. [Image] Specify 10 to send the notification immediately. [Image] Specify 5 to send the notification based on power considerations on the user’s device. [Image] Specify 1 to prioritize the device’s power considerations over all other factors for delivery, and prevent awakening the device.

apns-push-type

Required

The allowed value is Liveactivity.

Put the JSON payload with the notification’s content into the body of your request. Don’t use a compressed JSON payload, and the payload is limited to a maximum size of 5 KB (5,120 bytes).

The code snippet below shows a sample request constructed with an authentication token to the development enviroment.

HEADERS
  - END_STREAM
  + END_HEADERS
  :method = POST
  :scheme = https
  :path = 4/broadcasts/apps/com.example.MyApp
  host = api-broadcast.sandbox.push.apple.com
  authorization = bearer eyAia2lkIjogIjhZTDNHM1JSWDciIH0.eyAiaXNzIjogIkM4Nk5WOUpYM0QiLCAiaWF0I
         jogIjE0NTkxNDM1ODA2NTAiIH0.MEYCIQDzqyahmH1rz1s-LFNkylXEa2lZ_aOCX4daxxTZkVEGzwIhALvkClnx5m5eAT6
         Lxw7LZtEQcH6JENhJTMArwLf3sXwi
  apns-id = eabeae54-14a8-11e5-b60b-1697f925ec7b
  apns-push-type = liveactivity
  apns-expiration = 0
  apns-priority = 10
  apns-channel-id = dHN0LXNyY2gtY2hubA==
DATA
  + END_STREAM
  {
    "aps": {
        "timestamp": 1685952000,
        "event": "update",
        "content-state": {
            "currentHealthLevel": 0.0,
            "eventDescription": "Power Panda has been knocked down!"
        },
        "alert": {
            "title": {
                "loc-key": "%@ is knocked down!",
                "loc-args": ["Power Panda"]
            },
            "body": {
                "loc-key": "Use a potion to heal %@!",
                "loc-args": ["Power Panda"]
            },
            "sound": "HeroDown.mp4"
        }
    }
}

The code snippet below shows a sample request constructed for use with a certificate.

HEADERS
  - END_STREAM
  + END_HEADERS
  :method = POST
  :scheme = https
  :path = 4/broadcasts/apps/com.example.MyApp
  host = api-broadcast.sandbox.push.apple.com
  apns-request-id = eabeae54-14a8-11e5-b60b-1697f925ec7b
  apns-push-type = liveactivity
  apns-expiration = 0
  apns-priority = 10
  apns-channel-id = dHN0LXNyY2gtY2hubA==
DATA
  + END_STREAM
  {
    "aps": {
        "timestamp": 1685952000,
        "event": "update",
        "content-state": {
            "currentHealthLevel": 0.0,
            "eventDescription": "Power Panda has been knocked down!"
        },
        "alert": {
            "title": {
                "loc-key": "%@ is knocked down!",
                "loc-args": ["Power Panda"]
            },
            "body": {
                "loc-key": "Use a potion to heal %@!",
                "loc-args": ["Power Panda"]
            },
            "sound": "HeroDown.mp4"
        }
    }
}

APNs provides a response to each POST request your server transmits. Each response contains a header with fields indicating the status of the response. If the request succeeded, the body of the response is empty. A successful request provides the following fields in the response.

Header name

value

:status

200 A HTTP success status code

apns-request-id

The request identifier specified in the corresponding request. If not specified, the server generates the request identifier.

apns-unique-id

A server-generated unique message identifier returned in case of a successful request. Specify a unique identifier when raising troubleshooting requests with Apple.

Pay attention to status returned by APNs for each push notification and take appropriate action for your application in case of error. For more information on how to handle error responses, refer to Handling error responses from Apple Push Notification service

See Also

Broadcast push notifications