
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@notificationapi/react-native
Advanced tools
React Native SDK for NotificationAPI - Push notifications for Android and iOS
A React Native SDK for integrating NotificationAPI push notifications into your mobile app.
Cross-platform push notifications with native performance:
This means you get native push notifications on both platforms with optimal performance.
npm install @notificationapi/react-native
# or
yarn add @notificationapi/react-native
import NotificationAPI from '@notificationapi/react-native';
// That's it! This handles initialization, user identification, and permission requests
await NotificationAPI.setup({
clientId: 'your_client_id_here',
userId: 'user123',
autoRequestPermission: true, // automatically request push permissions
region: 'us' // 'us' (default), 'eu', or 'ca'
});
import { getEventEmitter, Events } 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);
});
// Check if SDK is ready
if (NotificationAPI.isReady) {
console.log('NotificationAPI is ready!');
}
// Get the current user
const userId = NotificationAPI.currentUser;
// Get push token
const token = await NotificationAPI.getPushToken();
import React, { useEffect } from 'react';
import { View, Button, Alert } from 'react-native';
import NotificationAPI, { getEventEmitter, Events } from '@notificationapi/react-native';
function App() {
useEffect(() => {
// Setup NotificationAPI
NotificationAPI.setup({
clientId: 'your_client_id',
userId: 'user123',
autoRequestPermission: true,
}).catch((error) => {
console.error('Failed to setup NotificationAPI:', error);
});
// Listen for notifications
const eventEmitter = getEventEmitter();
const receivedListener = eventEmitter.addListener(
Events.NOTIFICATION_RECEIVED,
(notification) => {
Alert.alert('New Notification', notification.title);
}
);
const clickListener = eventEmitter.addListener(
Events.NOTIFICATION_ON_CLICK,
(notification) => {
Alert.alert('Notification Clicked', notification.title);
// Handle navigation or deep linking
}
);
return () => {
receivedListener.remove();
clickListener.remove();
};
}, []);
const handleRequestPermission = async () => {
const granted = await NotificationAPI.requestPermission();
Alert.alert(
'Permission',
granted ? 'Permission granted' : 'Permission denied'
);
};
return (
<View>
<Button
title="Request Permission"
onPress={handleRequestPermission}
/>
</View>
);
}
export default App;
Background notifications are automatically handled by the native modules. The SDK uses:
No additional setup is required for basic background notification handling.
When users tap a notification while the app is terminated, it's automatically handled:
const eventEmitter = getEventEmitter();
eventEmitter.addListener(Events.NOTIFICATION_ON_CLICK, (notification) => {
console.log('Notification tapped:', notification.title);
// Handle deep linking or navigation
if (notification.data?.deepLink) {
// Navigate to specific screen
navigation.navigate(notification.data.deepLink);
}
});
| Method | Description | Returns |
|---|---|---|
setup(options) | One-call setup with initialization, identification, and optional permission request | Promise<void> |
requestPermission() | Request push notification permission | Promise<boolean> |
getPushToken() | Get the current push token (FCM on Android, APN on iOS) | Promise<string | null> |
getDeviceInfo() | Get device information | Promise<Device> |
getService() | Get the API service instance for advanced usage | NotificationAPIService |
await NotificationAPI.setup({
clientId: string, // Your NotificationAPI client ID (required)
userId: string, // User's unique identifier (required)
hashedUserId?: string, // Hashed user ID for privacy (optional)
region?: string, // 'us' (default), 'eu', or 'ca'
autoRequestPermission?: boolean, // Auto-request push permission (default: true)
baseUrl?: string, // Custom base URL (overrides region)
});
NotificationAPI.isReady (boolean): Check if SDK is initializedNotificationAPI.currentUser (string | null): Get current user IDEmitted when notification permission is requested.
Event data:
{
isGranted: boolean;
}
Emitted when a notification is clicked/tapped.
Event data:
{
messageId: string;
senderId: string;
ttl: number;
title: string;
body: string;
data: Record<string, unknown>;
}
Emitted when a push token is received.
Event data:
{
token: string;
type: 'FCM' | 'APN';
}
Emitted when a notification is received (foreground).
Event data:
{
messageId: string;
senderId: string;
title: string;
body: string;
data?: Record<string, unknown>;
}
Note: This SDK uses TurboModule (React Native's New Architecture), which requires React Native 0.73.0 or higher. If you're using React Native 0.68-0.72, you'll need to enable the New Architecture manually.
The setup process is as follows:
If you haven't already set up Firebase for your React Native Android app, follow Google's official documentation:
This will guide you through:
google-services.json file in android/app/build.gradle filesNote: Firebase dependencies (
firebase-messaging) are automatically included when you install the NotificationAPI React Native SDK. You don't need to manually add Firebase dependencies to yourbuild.gradlefiles.
Note: Permissions (
INTERNETandPOST_NOTIFICATIONS) and theFirebaseMessagingServiceregistration are automatically handled by the SDK via Android's manifest merger. You don't need to manually add these to yourAndroidManifest.xml.
To allow NotificationAPI to send notifications on your behalf, you need to provide it with your Firebase project's credentials.
Treat this file like a password. Never commit it to version control or expose it in your client-side application.
{}) into the field and save.Your NotificationAPI account is now connected to your Firebase project.
Our React Native SDK makes it easy to register the device for push notifications.
Install the SDK:
npm install @notificationapi/react-native
# or
yarn add @notificationapi/react-native
Then, initialize the SDK in your app (e.g., in App.tsx or your main component):
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'
});
This will automatically handle requesting push permissions and registering the device token with NotificationAPI.
Install CocoaPods dependencies (if using CocoaPods):
cd ios && pod install && cd ..
Enable Push Notifications capability in Xcode:
Configure APN:
-----BEGIN PRIVATE KEY-----
[your key content here]
-----END PRIVATE KEY-----
Update AppDelegate (if needed):
The SDK handles most of the setup, but you may need to ensure your AppDelegate.m or AppDelegate.swift properly handles APN token registration:
// Swift
import UserNotifications
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let token = deviceToken.map { String(format: "%02x", $0) }.joined()
UserDefaults.standard.set(token, forKey: "apns_token")
}
// Objective-C
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet:
[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
[[NSUserDefaults standardUserDefaults] setObject:token forKey:@"apns_token"];
}
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
React Native SDK for NotificationAPI - Push notifications for Android and iOS
We found that @notificationapi/react-native demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.