In-App UI
Expo
SDK
Push notifications

Handling Push Notifications with React Native and Expo

A guide on integrating Expo push notifications with the Knock SDK in your React Native application.

Note: This guide assumes you're utilizing our KnockExpoPushNotificationProvider for a streamlined push notification setup within your React Native and Expo environment.

Prerequisites

#

Before diving into the integration process, ensure your Knock account is set up for push notifications. For initial setup instructions, please visit our Push Notification Configuration Guide.

1

Setting Up Push Notifications with Expo

  1. Create a Push Notification Channel in Knock:

    • Log in to your Knock account and navigate to the Integrations > Channels section of the dashboard.
    • Create a new channel with type Expo Push Notifications and note the channel ID.
  2. Install Expo Dependencies:

    • expo": "~50.0.14
    • expo-constants": "^15.4.0
    • expo-device": "^5.9.3
    • expo-notifications": "^0.27.6
2

Registering for Push Notifications

  1. Wrap Your App with KnockExpoPushNotificationProvider:
    • Ensure your app is wrapped with KnockProvider and then KnockExpoPushNotificationProvider, passing the Expo channel ID from Knock.
  1. Initiate Registration in Your Component:
    • The KnockExpoPushNotificationProvider automatically registers for push notifications.
    • If you want to manually register, utilize the useExpoPushNotifications hook:
3

Handling Incoming Push Notifications

The KnockExpoPushNotificationProvider automatically handles receiving and tapping on notifications. To customize this behavior:

  1. Custom Notification Handling:
    • Use the onNotificationReceived and onNotificationTapped methods from the useExpoPushNotifications hook to set custom handlers.
4

Sending Test Notifications

Use the Knock dashboard or API to send a test notification to ensure your setup is correct. Verify that the notification appears on your device and that tapping on it triggers the expected behavior.

Troubleshooting

#
  • Not Receiving Notifications: Ensure your Expo push token is correctly registered with Knock and that your device's notification settings allow push notifications from your app.
  • Handling Silent Notifications: If implementing silent notifications, ensure that your notification payload is correctly configured to not display an alert or sound.

For further assistance, reach out to our support team.