Handling Push Notifications with React Native and Firebase Cloud Messaging
A guide on integrating FCM push notifications with the Knock SDK in your React Native application.
1
Set up a Firebase Cloud Messaging channel in Knock
If you haven't already, create a new Firebase Cloud Messaging channel in the Integrations page of your Knock dashboard. Follow our Firebase Cloud Messaging push notification guide to configure FCM with Knock using your Service Account JSON file.
2
Set up React Native Firebase
The simplest way to get started with FCM in your React Native app is to use React Native Firebase, which simplifies the process of handling push notifications and device tokens. Follow their Getting Started guide to set up React Native Firebase in your project.
3
Add KnockPushNotificationProvider to your app
Ensure your app is wrapped with both KnockProvider and KnockPushNotificationProvider.
Additionally, when your app is in the foreground, register a listener using onTokenRefresh and invoke registerPushTokenToChannel whenever the token is refreshed.
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 FCM device 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.