Push Notifications for React Native: FCM and APNs Setup
Register iOS and Android push tokens with Tappd, track notification opens, and manage push subscription status using Firebase Cloud Messaging and APNs.
Tappd lets you register device push tokens from Firebase Cloud Messaging (FCM) on Android and Apple Push Notification Service (APNs) on iOS, then send targeted push notifications through the Tappd platform. This guide walks you through requesting permissions, retrieving tokens, registering them with the SDK, and handling incoming notifications on both platforms.
Register a background handler in your index.js entry file. This runs in a
separate context, so the main SDK instance may not be available.
// index.jsimport messaging from '@react-native-firebase/messaging';messaging().setBackgroundMessageHandler(async (remoteMessage) => { console.log('Background message:', remoteMessage); // The SDK instance may not be initialized here. // If you need to track receipt, call the Tappd API directly.});
Register setBackgroundMessageHandler() in index.js before
AppRegistry.registerComponent(). It must be registered at module load
time, not inside a React component.
Track when users open the app by tapping a notification. Handle both
cold-start (app was closed) and warm-start (app was backgrounded) cases:
import messaging from '@react-native-firebase/messaging';// Cold start — app launched by tapping the notificationmessaging() .getInitialNotification() .then(async (remoteMessage) => { if (remoteMessage) { await tappd.trackPushOpen(remoteMessage); } });// Warm start — app was already running or backgroundedmessaging().onNotificationOpenedApp(async (remoteMessage) => { await tappd.trackPushOpen(remoteMessage);});
If registerPushToken() throws an error or the token doesn’t appear in the
Tappd dashboard:
Ensure identify() was called first — the SDK requires a known user before it can associate a device token.
Check FCM/APNs configuration — on iOS, confirm the APNs key or certificate is uploaded to Firebase Console. On Android, confirm google-services.json is in android/app/.
Verify network connectivity — token registration requires an active internet connection.
Check your error logs — wrap registerPushToken() in try-catch and log any caught errors.
Notifications not being received
If push notifications aren’t arriving on the device:
Verify the token is registered — check the Tappd dashboard to confirm the device appears under the user’s profile.
Check subscription status — call tappd.checkPushSubscription() and inspect the status field.
Verify FCM/APNs setup — use the Firebase Console’s test message tool to send a direct test notification to the token.
Check device permissions — on iOS, go to Settings → Notifications and confirm notifications are allowed for your app.