Handling notification responses from APNs
Respond to the status codes that the APNs servers return.
Overview
Apple Push Notification service (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 was successful, the body of the response is empty. If an error occurred, the body contains a JSON dictionary with additional information about the error.
If you find your device is having trouble receiving notifications, refer to Troubleshooting push notifications.
Interpret header responses
The table below describes the meaning of the keys in the header response.
Header name | Value |
|---|---|
| The same value found in the |
| The HTTP status code. |
| An identifier that is only available in the Development environment. Use this to query Delivery Log information for the corresponding notification in Push Notifications Console. For more information, refer to Testing Notifications Using The Push Notification Console. |
The table below lists the possible values in the :status header of the response.
Status code | Description |
|---|---|
| Success. |
| Bad request. |
| There was an error with the certificate or with the provider’s authentication token. |
| The request contained an invalid |
| The request used an invalid |
| The device token is no longer active for the topic. |
| The notification payload was too large. |
| The server received too many requests for the same device token. |
| Internal server error. |
| The server is shutting down and unavailable. |
Understand error codes
The table below lists the keys found in the JSON dictionary for unsuccessful requests. The JSON data might also be included in a GOAWAY frame when a connection terminates.
Key | Description |
|---|---|
| The error code (specified as a string) indicating the reason for the failure. For a list of possible values, refer to the Response error strings table below. |
| The time, represented in milliseconds since Epoch, at which APNs confirmed the token was no longer valid for the topic. This key is included only when the error in the |
The table below lists the possible error codes included in the reason key of a response’s JSON payload.
Status code | Error string | Description |
|---|---|---|
|
| The collapse identifier exceeds the maximum allowed size. |
|
| The specified device token is invalid. Verify that the request contains a valid token and that the token matches the environment. |
|
| The |
|
| The |
|
| The |
|
| The |
|
| The device token doesn’t match the specified topic. |
|
| One or more headers are repeated. |
|
| Idle timeout. |
|
| The |
|
| The device token isn’t specified in the request |
|
| The |
|
| The message payload is empty. |
|
| Pushing to this topic is not allowed. |
|
| The certificate is invalid. |
|
| The client certificate doesn’t match the environment. |
|
| The provider token is stale and a new token should be generated. |
|
| The specified action is not allowed. |
|
| The provider token is not valid, or the token signature can’t be verified. |
|
| No provider certificate was used to connect to APNs, and the |
|
| The key ID in the provider token isn’t related to the key ID of the token used in the first push of this connection. To use this token, open a new connection. |
|
| The key ID in the provider token doesn’t match the environment. |
|
| The request contained an invalid |
|
| The specified |
|
| The device token has expired. |
|
| The device token is inactive for the specified topic. There is no need to send further pushes to the same device token, unless your application retrieves the same device token, refer to Registering Your App With Apns |
|
| The message payload is too large. For information about the allowed payload size, refer to Create a POST request to APNs in Sending Notification Requests To Apns. |
|
| The provider’s authentication token is being updated too often. Update the authentication token no more than once every 20 minutes. |
|
| Too many requests were made consecutively to the same device token. |
|
| An internal server error occurred. |
|
| The service is unavailable. |
|
| The APNs server is shutting down. |
After 15 minutes, you can retry JSON payloads that receive response status codes that begin with 5XX. While retrying, you may employ a back-off technique. Most notifications with the status code 4XX can be retried after you fix the error noted in the reason field. Don’t retry notification responses with the error code BadDeviceToken, DeviceTokenNotForTopic, Forbidden, ExpiredToken, Unregistered, or PayloadTooLarge. You can retry with a delay, if you get the error code TooManyRequests.
The code listing below shows a sample response for a successful push request.
HEADERS
+ END_STREAM
+ END_HEADERS
apns-id = eabeae54-14a8-11e5-b60b-1697f925ec7b
:status = 200The code listing below shows a sample response when an error occurs.
HEADERS
- END_STREAM
+ END_HEADERS
:status = 400
content-type = application/json
apns-id: <a_UUID>
DATA
+ END_STREAM
{ "reason" : "BadDeviceToken" }During testing, if you find that your test devices aren’t receiving push notifications sent by your provider server, see, Troubleshooting push notifications to troubleshoot.