React Native SDK

The React Native SDK is used for push notifications on Android and iOS mobile apps.

Requirements

  • React Native: >= 0.73.0
  • React: >= 18.0.0
  • New Architecture: Required (enabled by default in React Native 0.73+)
WARNING

Important: This SDK uses TurboModule (React Native’s New Architecture), which requires React Native 0.73.0 or higher.

Setup

npm install @notificationapi/react-native
yarn add @notificationapi/react-native

Initialization

import NotificationAPI from '@notificationapi/react-native';

// Initialize when your app starts
await NotificationAPI.setup({
  clientId: 'YOUR_CLIENT_ID', // from NotificationAPI dashboard
  userId: 'user123', // your app's user ID
  autoRequestPermission: true, // automatically request push permissions
  region: 'us' // 'us' (default), 'eu', or 'ca'
});

Setup Parameters

ParameterTypeDescription
clientId*stringYour NotificationAPI account clientId. You can get it from here.
userId*stringThe unique ID of the user in your system.
hashedUserIdstringHashed user ID for privacy (optional).
regionstringRegion code: 'us' (default), 'eu', or 'ca'.
autoRequestPermissionbooleanAutomatically request push notification permission (default: true).
baseUrlstringCustom base URL (overrides region).

API Reference

NotificationAPI.setup(options)

Initialize the SDK with user credentials.

Parameters:

  • clientId (string, required): Your NotificationAPI client ID
  • userId (string, required): The user’s unique identifier
  • hashedUserId (string, optional): Hashed user ID for privacy
  • region (string, optional): Region code - ‘us’ (default), ‘eu’, or ‘ca’
  • autoRequestPermission (boolean, optional): Automatically request push permission (default: true)
  • baseUrl (string, optional): Custom base URL (overrides region)

Returns: Promise<void>

NotificationAPI.requestPermission()

Request push notification permission.

Returns: Promise<boolean> - true if permission was granted

NotificationAPI.getPushToken()

Get the current push token (FCM on Android, APN on iOS).

Returns: Promise<string | null>

NotificationAPI.getDeviceInfo()

Get device information.

Returns: Promise<Device> - Device object with device_id, platform, manufacturer, model, etc.

Properties

  • NotificationAPI.isReady (boolean): Check if SDK is initialized
  • NotificationAPI.currentUser (string | null): Get current user ID

Events

Listening to Events

import { Events, getEventEmitter } from '@notificationapi/react-native';

const eventEmitter = getEventEmitter();

// Listen to notifications received while app is open
eventEmitter.addListener(Events.NOTIFICATION_RECEIVED, (notification) => {
  console.log('Received notification:', notification.title);
});

// Listen to notifications that opened the app
eventEmitter.addListener(Events.NOTIFICATION_ON_CLICK, (notification) => {
  console.log('App opened from notification:', notification.title);
  // Handle deep linking or navigation
});

// Listen to push token updates
eventEmitter.addListener(Events.PUSH_TOKEN_RECEIVED, (event) => {
  console.log('Push token received:', event.token);
});

Events.NOTIFICATION_PERMISSIONS_REQUESTED

Emitted when notification permission is requested.

Event data:

{
  isGranted: boolean;
}

Events.NOTIFICATION_ON_CLICK

Emitted when a notification is clicked/tapped.

Event data:

{
  messageId: string;
  senderId: string;
  ttl: number;
  title: string;
  body: string;
  data: Record<string, unknown>;
}

Events.PUSH_TOKEN_RECEIVED

Emitted when a push token is received.

Event data:

{
  token: string;
  type: 'FCM' | 'APN';
}

Events.NOTIFICATION_RECEIVED

Emitted when a notification is received (foreground).

Event data:

{
  messageId: string;
  senderId: string;
  title: string;
  body: string;
  data?: Record<string, unknown>;
}

Platform-Specific Setup

Android

  • Requires Firebase Cloud Messaging (FCM) setup
  • Background notifications are handled automatically
  • Foreground notifications can be customized via event listeners
  • See Android Setup Guide for detailed instructions

iOS

  • Uses native APN (Apple Push Notifications)
  • Requires Apple Developer Program membership
  • Push Notifications capability must be enabled in Xcode
  • APN keys must be configured in NotificationAPI dashboard
  • Environment (sandbox/production) is determined by your build configuration
  • See iOS Setup Guide for detailed instructions

Troubleshooting

Push tokens not syncing

  • Android: Verify Firebase is properly configured and google-services.json is in the correct location
  • iOS: Ensure APN is properly configured and the app has push notification capabilities enabled
  • Check that NotificationAPI.setup() completed successfully

Notifications not received

  • Verify permission was granted: await NotificationAPI.requestPermission()
  • Check that your NotificationAPI client ID is correct
  • Ensure push tokens are being synced (check getPushToken())
  • Android:
    • Verify Firebase project includes your app’s package name
    • Ensure FirebaseMessagingService is created in your app’s package
    • Check that the service is registered in AndroidManifest.xml
    • Check logs: adb logcat | grep NotificationAPI
  • iOS: Ensure APN keys are correctly configured

ClassNotFoundException for FirebaseMessagingService

  • Ensure the service file is in your app’s package directory
  • Verify the package name in the service file matches your app’s package
  • Check that the service is registered in AndroidManifest.xml with the correct package path
  • Clean and rebuild: cd android && ./gradlew clean && cd .. && npx react-native run-android

Permission denied

  • Android: Check app notification settings in device settings
  • iOS: Check notification settings in iOS Settings app
  • Try calling requestPermission() again