How to send push notifications to Apple Push Notifications service

In this guide we'll walk through how to configure an Apple Push Notifications service (APNS) provider in Knock to send iOS push notifications. This guide assumes that you've already created an APNS channel in the Knock dashboard.

🔔
APNS server certificate update. Your team may have received an update from Apple regarding the need to update the server certificates in your application's Trust Store prior to February 24, 2025.

When you send notifications through Knock, we manage this server-side Trust Store on your behalf. You do not need to make any updates to your Knock channel configuration or to your mobile application in order to continue sending APNS push notifications via Knock.

How to configure Apple Push Notifications service with Knock

There are two ways to configure APNS with Knock. You can use a token-based authentication scheme or a certificate-based authentication scheme. Depending on which you choose, you'll need to get different information from Xcode and your Apple developer account.

Token-based authentication configuration

Note: Knock recommends token-based authentication for all APNS channel connections.

You can read about how to set up a token connection to APNS in the documentation. For your Knock channel configuration, you will need:

  1. A provider token signing key (a private key)
  2. The key identifier (a 10 digit identifier from your Apple developer account)
  3. The team identifier (a 10 digit identifier from your Apple developer account)

Certificate-based authentication configuration

You can read about how to set up a certificate connection to APNS in the documentation. For your Knock channel configuration, you will need:

  1. A provider certificate (from your Apple developer account)
  2. A private key (generated in the process above)

Both of these values should be converted according to the instructions here prior to providing them to your Knock channel configuration.

Using APNS with Knock

In order to use APNS with Knock you'll need to synchronize your users device tokens retrieved from the APNS SDK to Knock by setting channel data for your recipient.

You can follow the quickstart guide on APNS to see how to get the device token.

Managing tokens

By default, Knock makes no assumptions about managing your device tokens. This means you are responsible for removing tokens when a recipient opts out of notifications on a device or when their token expires.

However, Knock does provide an opt-in token deregistration feature that automatically removes invalid tokens from a recipient's channel data when a message bounces. When enabled, Knock will automatically remove invalid or expired tokens upon receiving a bounce event from the provider.

You can configure token deregistration on a per-environment basis in your channel's environment configurations. See our token deregistration guide for more details on enabling and working with this feature.

Data passed to APNS

When sending a notification to APNS, we also pass through the following attributes:

PropertyTypeDescription
knock_message_id*stringThe message ID of the corresponding Knock message
data *stringAny key/value data passed through in your trigger call

Silent/background notifications

We support sending APNS notifications as "silent", data-only notifications within Knock. You can enable this per push notification template by clicking "Manage template settings" in the header of the template editor.

When silent push is enabled, we'll no longer pass through the content payload and your message will be sent with the content-available: 1 flag as expected by APNS. All properties in the data payload described above will be sent with your notification.

Using overrides to customize notifications

We have full support for overriding the payload sent to APNS for adding things like badge counts, extra data properties, and sound files. You can set push overrides on the template settings modal, which is accessed by clicking on the "Manage template settings" button when viewing a push notification template within the workflow editor. Push overrides support Liquid for injecting data properties and referencing attributes on your recipients.

Overrides are merged into the notification payload sent to APNS. See the APNS documentation for more details.

PropertyTypeDescription
headersdictionaryAPNS specific headers (apns-priority, apns-expiration, apns-push-type, apns-topic, apns-collapse-id)
apsdictionaryOverrides to send to the push payload (sound, alert, badge, thread-id)
anyanyAny other key values to send as part of the push message

Channel data requirements

In order to use a configured APNS channel you must store a list of one or more device tokens for the user or the object that you wish to deliver a notification to. You can retrieve a device token by following the guide on the Apple developer documentation.

PropertyTypeDescription
tokens*string[]One or more device tokens