React Native SDK Setup
Integrate Push Notifications into your React Native app to receive and handle push notifications on both Android and iOS.
v1.0.5-beta. Not for production use. Pin the exact version. APIs may change without notice.
- Make sure to configure the App ID properly. For additional information see Getting started
- Configure your push credentials in the AppsOnAir console under App Settings → Push Notifications — upload your Firebase service account JSON (Android) and APNs Auth Key (iOS) before sending any notifications.
Requirements
| Minimum | |
|---|---|
| React Native | 0.71+ |
| iOS | 15.0 |
| Android | API 24 (Android 7.0) |
| Kotlin | 1.9+ |
The library supports both the New Architecture (Fabric / TurboModules) and the Old Architecture — the same JavaScript API works with either native implementation.
Basic push — Steps 1–4 only. No iOS extension targets needed:
- Text notifications with title and body
- Tap-to-open and deep links
- Foreground display control
- Images on Android (download automatically via the data payload — no extra setup)
- User targeting, tags, segments, opt-in / opt-out
Advanced push (iOS only) — requires additional extension targets. Skip these if you only need basic push:
| Feature | Additional setup |
|---|---|
| Images on iOS | Notification Service Extension (NSE) |
| Badge auto-increment | NSE + App Group |
| Delivered analytics | NSE + App Group |
| Custom long-press view | NSE + Notification Content Extension (NCE) |
Silent push (background data, no visible notification) is supported on both platforms with no extra targets. See Silent Push.
Step 1: Install the Package
npm install [email protected]
Then for iOS, install native pods:
cd ios && pod install
Autolinking handles the rest — no manual additions to native files needed.
Step 2: Android Setup
Firebase Configuration
Push Notifications uses Firebase Cloud Messaging (FCM) for Android delivery.
- Open the Firebase Console and add your Android app.
- Download
google-services.jsonand place it inandroid/app/.
Gradle Configuration
The native Android SDK is hosted on JitPack. The React Native template uses Groovy Gradle files:
buildscript {
dependencies {
// ...existing classpaths
classpath("com.google.gms:google-services:4.4.2")
}
}
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
apply plugin: "com.google.gms.google-services"
If your project declares repositories in android/settings.gradle (dependencyResolutionManagement), add maven { url 'https://jitpack.io' } there instead of allprojects.
Notification Icon & Color
The icon and color setup is identical to the native Android SDK. Place your icon in android/app/src/main/res/drawable* and declare both the AppsOnAir and Firebase meta-data entries in android/app/src/main/AndroidManifest.xml.
See Android SDK → Notification Icon & Color for the full setup — the only difference is the android/app/ path prefix on all resource folders.
Step 3: iOS Setup
Capabilities & Info.plist
The required Xcode capabilities (Push Notifications, Background Modes → Remote notifications) and Info.plist keys (AppsonairAppId) are the same as the native iOS SDK.
See iOS SDK → Apple Capabilities and iOS SDK → Configure Info.plist for the full setup. File paths are inside ios/<YourApp>/ instead of the Xcode project root.
iOS: Notification Service Extension (Optional — Rich Push)
Steps 1–4 are all you need for basic push notifications — text, tap-to-open, and deep links. The NSE and NCE are optional iOS extensions you add only when you need:
| Feature | Requires |
|---|---|
| Images in notifications | NSE |
| Badge auto-increment | NSE + App Group |
| Delivered analytics | NSE + App Group |
| Custom expanded view (long-press) | NSE + NCE |
Android needs nothing extra for images — they download automatically.
iOS shows images only when an NSE downloads them. The NSE also records Delivered analytics and applies badge increments. Android needs nothing extra.
The concept and most steps are the same as the native iOS SDK — see iOS SDK → Notification Service Extension for the full walkthrough.
React Native-specific: add the NSE via CocoaPods Podfile
The React Native package brings in AppsOnAir-AppPush via CocoaPods, so the NSE links via the AppsOnAir-AppPush-ServiceExt pod — not SPM. Add the NSE as a top-level target (outside your app target):
target 'YourApp' do
# ...existing React Native setup
end
target 'NotificationService' do
pod 'AppsOnAir-AppPush-ServiceExt', '1.0.6-beta'
end
Then run cd ios && pod install. In NotificationService.swift, import AppsOnAir_AppPush_ServiceExt:
import AppsOnAir_AppPush_ServiceExt
class NotificationService: AppsOnAirNotificationServiceExtension {}
Xcode 16 adds new targets as synchronized folders, which CocoaPods can't read yet. Right-click the extension's folder → Convert to Group before running pod install.
ServiceExtension subspecThe AppsOnAir-AppPush/ServiceExtension subspec is deprecated. With use_frameworks! it fails at archive time with "Multiple commands produce AppsOnAir_AppPush.framework". Replace it with pod 'AppsOnAir-AppPush-ServiceExt', '1.0.6-beta', change the import from AppsOnAir_AppPush to AppsOnAir_AppPush_ServiceExt, run pod install, and remove any post_install workaround that renamed the extension's framework.
iOS: Notification Content Extension (Optional — Custom Long-Press View)
The NCE replaces the long-press view with the SDK's built-in image + title + body layout. It depends on the NSE for the image.
The setup steps are the same as the native iOS SDK — see iOS SDK → Notification Content Extension for the full walkthrough.
React Native-specific: add the NCE via CocoaPods Podfile
target 'NotificationContent' do
pod 'AppsOnAir-AppPush-ContentExt', '1.0.6-beta'
end
Then run cd ios && pod install. Also Convert to Group in Xcode 16+ (same as NSE above).
Import AppsOnAir_AppPush_ContentExt in the view controller. The AppsOnAir-AppPush/ContentExtension subspec is deprecated, for the same reason as the NSE subspec.
Step 4: Initialize the SDK
Initialize as early as possible — in index.js or in your root component's useEffect.
import AppPushService from 'appsonair-react-native-apppush';
// Initialize at app startup
await AppPushService.initialize({ debug: __DEV__ });
On iOS the SDK hooks the notification delegate automatically. It works alongside other libraries that set the delegate, such as Notifee: AppsOnAir pushes still reach the SDK and the other library keeps receiving its own notifications.
Feature Guides
Subscribe to Events
Subscribe once near app start and keep the subscription for the app's lifetime.
// Foreground notification received
const sub1 = AppPushService.onNotificationReceived(({ notification }) => {
console.log('Received:', notification.title);
});
// User tapped the notification
const sub2 = AppPushService.onNotificationOpened(({ notification }) => {
console.log('Opened:', notification.id);
});
// Token updated
const sub3 = AppPushService.onTokenUpdated(({ token }) => {
console.log('Token:', token);
});
// Clean up on unmount
return () => {
sub1.remove();
sub2.remove();
sub3.remove();
};
Available Events
Each method returns a subscription. Call .remove() on it to stop listening.
| Method | Fires when | Event data |
|---|---|---|
onNotificationReceived | A notification arrives while the app is in the foreground | { notification } |
onNotificationOpened | The user taps a notification or one of its action buttons | { notification, actionId, url } |
onNotificationWillDisplay | In the foreground, before a notification is shown | { notification, preventDefault } |
onTokenUpdated | The push token is issued or refreshed | { token, environment } |
onPermissionChanged | The OS notification permission changes | { granted } |
onSubscriptionChanged | The subscription's token or opt-in state changes | { previous, current } |
onUserStateChanged | login() or logout() is called | { current } |
onSilentNotification | A data-only push arrives and isn't displayed | { data } |
onError | A background SDK operation fails | { code, message } |
onInstallationIdUpdated | The Firebase Installation ID becomes available (Android only) | { id } |
Events fired before you subscribe are not replayed. Subscribe as early as possible — before or immediately after initialize() — to avoid missing events.
Event Data
| Event | Field | Type | Description |
|---|---|---|---|
onNotificationReceived | notification | PushNotification | The received notification. See the notification fields below |
onNotificationOpened | notification | PushNotification | The tapped notification |
onNotificationOpened | actionId | string | null | ID of the tapped action button. null when the notification body was tapped |
onNotificationOpened | url | string | null | The payload's launch URL, if any |
onNotificationWillDisplay | notification | PushNotification | The notification about to be shown |
onNotificationWillDisplay | preventDefault | () => void | Call synchronously to hide the notification. Android only; on iOS it's already shown |
onTokenUpdated | token | string | APNs hex token (iOS) or FCM registration token (Android) |
onTokenUpdated | environment | 'sandbox' | 'production' | null | APNs environment. iOS only; null on Android |
onPermissionChanged | granted | boolean | true if notifications are now allowed |
onSubscriptionChanged | previous / current | PushSubscriptionState | State before and after the change: id (string | null), token (string | null), optedIn (boolean) |
onUserStateChanged | current.externalId | string | null | The ID passed to login(). null after logout() |
onUserStateChanged | current.appsOnAirId | string | The AppsOnAir-assigned device ID |
onSilentNotification | data | Record<string, string> | The push's custom keys. iOS: sent with content-available: 1. Android: the data payload must include silent: "true" |
onError | code | string | notInitialized, permissionDenied, firebaseNotConfigured (Android only), tokenRegistrationFailed, installationIdFetchFailed or unknown |
onError | message | string | Human-readable error description |
onInstallationIdUpdated | id | string | Firebase Installation ID |
Notification Fields
The notification object in onNotificationReceived, onNotificationOpened and onNotificationWillDisplay. A field a platform doesn't support is null (or []), never undefined.
| Field | Type | Payload key | Platform |
|---|---|---|---|
id | string | null | notification_id | Both |
title | string | null | Title | Both |
body | string | null | Body | Both |
subtitle | string | null | Subtitle | iOS only |
launchUrl | string | null | url (deep link opened on tap) | Both |
imageUrl | string | null | image_url | Both |
actionButtons | { id, title }[] | actions | Both |
collapseId | string | null | collapse_id (iOS) / collapse_key (Android) | Both |
data | Record<string, string> | All custom keys, as a flat string map | Both |
rawPayload | Record<string, unknown> | The complete payload. Prefer data | Both |
attachments | { id, url }[] | attachments | iOS only ([] on Android) |
badgeIncrement | number | null | badge_increment | iOS only |
campaignId | string | null | campaign_id | iOS only |
templateId | string | null | template_id | iOS only |
sentAt | string | null | sent_at (ISO-8601, as received) | iOS only |
sound | string | null | Sound file name in res/raw, without extension | Android only |
channelId | string | null | Notification channel ID | Android only |
Permission
const granted = await AppPushService.getPermission();
// Request
await AppPushService.requestPermission();
// Permanently denied? Open Settings:
await AppPushService.requestPermission({ fallbackToSettings: true });
const status = await AppPushService.getPermissionStatus();
User Identity
await AppPushService.login('user_12345');
await AppPushService.logout();
// Read back
const externalId = await AppPushService.getExternalId();
const deviceId = await AppPushService.getDeviceId();
Tags & Segmentation
await AppPushService.user.addTag('plan', 'premium');
await AppPushService.user.addTags({ plan: 'premium', region: 'us' });
await AppPushService.user.removeTag('plan');
// Note: Android fetches from backend; iOS uses local cache
const tags = await AppPushService.user.getTags();
Language
await AppPushService.user.setLanguage('fr'); // ISO 639-1 code
Aliases & Email
await AppPushService.user.addAlias('crm_id', 'CRM-9876');
await AppPushService.user.addAliases({ crm_id: 'CRM-9876' });
await AppPushService.user.removeAlias('crm_id');
await AppPushService.user.addEmail('[email protected]');
await AppPushService.user.removeEmail('[email protected]');
Each subscription keeps one email, so calling addEmail again replaces the previous address.
Opt-in / Opt-out
await AppPushService.user.optOut();
await AppPushService.user.optIn();
const optedIn = await AppPushService.user.getOptedIn();
Foreground Display
preventDefault() works only on Android. On iOS, notifications display synchronously before JavaScript executes.
AppPushService.onNotificationWillDisplay(({ notification, preventDefault }) => {
// Call synchronously — the SDK is waiting on this handler.
// Call preventDefault() to suppress the notification.
preventDefault();
});
Badge (Optional)
iOS uses the native badge API. Android uses launcher broadcasts (Samsung, MIUI, ASUS only).
await AppPushService.badge.set(5);
await AppPushService.badge.increment(1);
await AppPushService.badge.clear();
const count = await AppPushService.badge.get();
Silent Push (Optional)
A silent push delivers data to your app without showing a notification. Use it to refresh content or update local state. Subscribe with onSilentNotification. The push still counts as delivered in analytics.
const sub = AppPushService.onSilentNotification(({ data }) => {
console.log('Silent push received:', data);
// e.g. data.sync_type === 'orders' → refresh orders
});
// Clean up on unmount
return () => sub.remove();
To send a silent push from your backend, see REST API → Silent Notifications. The API builds the right payload for each platform.
Managing Delivered Notifications (Optional)
await AppPushService.notifications.clearAll();
await AppPushService.notifications.remove('order-4821');
await AppPushService.notifications.removeMany(['order-4821', 'order-4822']);
When Notifications Won't Be Delivered
Push delivery can be blocked by OS settings, device state, and manufacturer battery managers — not just your code. For the full breakdown of conditions per platform:
- Android — Doze, App Standby, battery optimization, OEM restrictions, force-stop → Android SDK → When Notifications Won't Be Delivered
- iOS — Low Power Mode, kill mode, Background App Refresh, Apple rate limiting, low battery → iOS SDK → When Notifications Won't Be Delivered
Send silent pushes as data-only FCM payloads (no notification block) with "silent": "true" in data. If a notification block is present, Firebase renders the notification itself and bypasses the SDK entirely.
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
| Token never arrives (Android) | Firebase not configured | Place google-services.json in android/app/ |
| Token never arrives (iOS) | Push capability missing | Add Push Notifications via Signing & Capabilities |
FIS_AUTH_ERROR in Logcat (Android) | Firebase API key rejected for this build | Follow FIS_AUTH_ERROR |
Token never arrives (Android); Logcat shows c2dm: [-19,ERR_SERVICE_NOT_AVAILABLE,0,0]; onError gives tokenRegistrationFailed | The device can't reach Firebase's servers (network, VPN, Private DNS, Play services or battery restrictions) | Follow SERVICE_NOT_AVAILABLE, then force-stop and relaunch the app |
| Permission not requested (iOS) | requestPermission() not called | Call after initialize() |
| No push in background (Android) | notification block in FCM payload | Send data-only payload for full SDK control |
| Silent push shown as a notification (Android) | silent key missing from data | Add "silent": "true" to the data payload |
onSilentNotification never fires (iOS) | Background Modes → Remote notifications missing, or payload has an alert | Enable the capability and send only content-available: 1 |
Cannot find module | Package not installed | Run npm install and npx pod-install |
| Swift runtime error (ObjC project) | Missing Swift stdlib | Add a blank .swift file to the Xcode project to force Swift runtime linkage |
| White square icon (Android) | Icon meta-data missing, or the icon is full-colour | Follow Notification Icon & Color |
| iOS images don't show | No NSE, or mutable-content missing | Set up the NSE and send mutable-content: 1 |
| NSE never runs | NSE deployment target is higher than the device's iOS | Lower the NSE's Minimum Deployments to your app's |
pod install: object version 70 | Xcode 16 synchronized folder | Right-click the extension folder → Convert to Group |
pod install still installs an older AppsOnAir-AppPush after upgrading | Podfile.lock is pinning it | Run pod update AppsOnAir-AppPush AppsOnAir-AppPush-ServiceExt |
pod install: "Unable to find a specification for AppsOnAir-AppPush-ServiceExt" | Local spec index is out of date | Run pod install --repo-update |
| Archive: "Multiple commands produce AppsOnAir_AppPush.framework" | Extension uses the deprecated AppsOnAir-AppPush/ServiceExtension subspec | Switch to the AppsOnAir-AppPush-ServiceExt pod and update the import (see the note in the NSE section) |
| NCE not shown on long-press | aps.category doesn't match UNNotificationExtensionCategory | Send the same category string |
| Doesn't work in Expo Go | Native modules and extensions need a native build | Use a development build |
Setup Checklist
Android
-
google-services.jsonis inandroid/app/, and the Google Services plugin is applied - JitPack is added to the repositories
-
AppsonairAppId, plus the AppsOnAir and Firebase icon/color meta-data, are inAndroidManifest.xml - A white-on-transparent icon is in
res/drawable*, and the color is inres/values/colors.xml
iOS
-
AppsonairAppIdis inInfo.plist, andpod installhas been run - Push Notifications and Background Modes → Remote notifications are enabled
- NSE: target added (deployment target matches the app),
AppsOnAir-AppPush-ServiceExtpod in the Podfile,AppsOnAirNotificationServiceExtensionsubclass, same App Group on app and NSE - NCE (optional): target added,
AppsOnAir-AppPush-ContentExtpod in the Podfile, storyboard removed, category set - Pushes send
mutable-content: 1(andaps.categoryfor the NCE)
JavaScript
-
AppPushService.initialize()runs at startup -
requestPermission()is called
Log Levels
Set before initialize():
await AppPushService.debug.setLogLevel('verbose'); // before initialize()
await AppPushService.initialize({ debug: __DEV__ });
Available levels: none, fatal, error, warn, info, debug, verbose.