KnockDocs

How to send push notifications using Expo

In this guide we'll walk through how to configure an Expo provider in Knock. This guide assumes that you've already created an Expo channel in the Knock dashboard and that your React Native application is already setup to support Push notifications.

If you're new to setting up push in your Expo enabled React Native project, you can follow the excellent setup guide in the Expo documentation.

How to configure Expo with Knock

To configure Expo with Knock, you'll need your Expo project name (sometimes referred to as an experience_id) and if you've enabled enhanced push security, you'll also need an auth token. You can read more about Enhanced Push Security in the Expo docs.

You can get both of these by logging into the Expo console. Once you have them, go back to the environment configuration for your Expo channel, complete the configuration, and you're good to go.

Using Expo with Knock

In order to use Expo with Knock you'll need to synchronize your users device tokens retrieved from the Expo SDK in either Android, iOS, or on the Web to Knock by setting channel data for your recipient.

You can follow the appropriate quickstart guide for your platform on Expo to see how to get the device token.

Managing tokens

Knock makes no assumptions about managing your device tokens for you. Meaning if a recipient opts-out of receiving notifications on a device, or the token expires, it is up to you to remove the token from the recipients channel data. This behavior is subject to change in the future.

Data passed to Expo

When sending a notification to Expo, 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 notify call

Silent/background notifications

We support sending Expo notifications as "silent", data-only notifications within Knock. You can enable this per push notification template under the 3-dot menu 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: true flag as expected by Expo. All properties in the data payload described above will be sent with your notification.

Customizing your notifications

If you need to further customize the payload sent to Expo when issuing your notification like adding custom badges or sounds, please reach out to us.

Channel data requirements

In order to use a configured Expo 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 Expo developer documentation.

PropertyTypeDescription
tokens*string[]One or more device tokens