Skip to main content

React Native SDK Setup

Integrate Push Notifications into your React Native app to receive and handle push notifications on both Android and iOS.


Beta Release

v1.0.5-beta. Not for production use. Pin the exact version. APIs may change without notice.

Essential Setup
  • 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 Native0.71+
iOS15.0
AndroidAPI 24 (Android 7.0)
Kotlin1.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 vs Advanced Push (Rich Notifications)

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:

FeatureAdditional setup
Images on iOSNotification Service Extension (NSE)
Badge auto-incrementNSE + App Group
Delivered analyticsNSE + App Group
Custom long-press viewNSE + 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.

  1. Open the Firebase Console and add your Android app.
  2. Download google-services.json and place it in android/app/.

Gradle Configuration​

The native Android SDK is hosted on JitPack. The React Native template uses Groovy Gradle files:

android/build.gradle
buildscript {
dependencies {
// ...existing classpaths
classpath("com.google.gms:google-services:4.4.2")
}
}

allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
android/app/build.gradle (bottom of file)
apply plugin: "com.google.gms.google-services"
note

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)​

Basic push works without the NSE

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:

FeatureRequires
Images in notificationsNSE
Badge auto-incrementNSE + App Group
Delivered analyticsNSE + 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):

ios/Podfile
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:

NotificationService.swift
import AppsOnAir_AppPush_ServiceExt

class NotificationService: AppsOnAirNotificationServiceExtension {}
Xcode 16+: Convert to Group

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.

Migrating from the ServiceExtension subspec

The 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

ios/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.

index.js or App.tsx
import AppPushService from 'appsonair-react-native-apppush';

// Initialize at app startup
await AppPushService.initialize({ debug: __DEV__ });
Works with other notification libraries

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.

Events
// 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.

MethodFires whenEvent data
onNotificationReceivedA notification arrives while the app is in the foreground{ notification }
onNotificationOpenedThe user taps a notification or one of its action buttons{ notification, actionId, url }
onNotificationWillDisplayIn the foreground, before a notification is shown{ notification, preventDefault }
onTokenUpdatedThe push token is issued or refreshed{ token, environment }
onPermissionChangedThe OS notification permission changes{ granted }
onSubscriptionChangedThe subscription's token or opt-in state changes{ previous, current }
onUserStateChangedlogin() or logout() is called{ current }
onSilentNotificationA data-only push arrives and isn't displayed{ data }
onErrorA background SDK operation fails{ code, message }
onInstallationIdUpdatedThe Firebase Installation ID becomes available (Android only){ id }
note

Events fired before you subscribe are not replayed. Subscribe as early as possible — before or immediately after initialize() — to avoid missing events.

Event Data​

EventFieldTypeDescription
onNotificationReceivednotificationPushNotificationThe received notification. See the notification fields below
onNotificationOpenednotificationPushNotificationThe tapped notification
onNotificationOpenedactionIdstring | nullID of the tapped action button. null when the notification body was tapped
onNotificationOpenedurlstring | nullThe payload's launch URL, if any
onNotificationWillDisplaynotificationPushNotificationThe notification about to be shown
onNotificationWillDisplaypreventDefault() => voidCall synchronously to hide the notification. Android only; on iOS it's already shown
onTokenUpdatedtokenstringAPNs hex token (iOS) or FCM registration token (Android)
onTokenUpdatedenvironment'sandbox' | 'production' | nullAPNs environment. iOS only; null on Android
onPermissionChangedgrantedbooleantrue if notifications are now allowed
onSubscriptionChangedprevious / currentPushSubscriptionStateState before and after the change: id (string | null), token (string | null), optedIn (boolean)
onUserStateChangedcurrent.externalIdstring | nullThe ID passed to login(). null after logout()
onUserStateChangedcurrent.appsOnAirIdstringThe AppsOnAir-assigned device ID
onSilentNotificationdataRecord<string, string>The push's custom keys. iOS: sent with content-available: 1. Android: the data payload must include silent: "true"
onErrorcodestringnotInitialized, permissionDenied, firebaseNotConfigured (Android only), tokenRegistrationFailed, installationIdFetchFailed or unknown
onErrormessagestringHuman-readable error description
onInstallationIdUpdatedidstringFirebase Installation ID

Notification Fields​

The notification object in onNotificationReceived, onNotificationOpened and onNotificationWillDisplay. A field a platform doesn't support is null (or []), never undefined.

FieldTypePayload keyPlatform
idstring | nullnotification_idBoth
titlestring | nullTitleBoth
bodystring | nullBodyBoth
subtitlestring | nullSubtitleiOS only
launchUrlstring | nullurl (deep link opened on tap)Both
imageUrlstring | nullimage_urlBoth
actionButtons{ id, title }[]actionsBoth
collapseIdstring | nullcollapse_id (iOS) / collapse_key (Android)Both
dataRecord<string, string>All custom keys, as a flat string mapBoth
rawPayloadRecord<string, unknown>The complete payload. Prefer dataBoth
attachments{ id, url }[]attachmentsiOS only ([] on Android)
badgeIncrementnumber | nullbadge_incrementiOS only
campaignIdstring | nullcampaign_idiOS only
templateIdstring | nulltemplate_idiOS only
sentAtstring | nullsent_at (ISO-8601, as received)iOS only
soundstring | nullSound file name in res/raw, without extensionAndroid only
channelIdstring | nullNotification channel IDAndroid only

Permission​

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​

Login / Logout
await AppPushService.login('user_12345');
await AppPushService.logout();

// Read back
const externalId = await AppPushService.getExternalId();
const deviceId = await AppPushService.getDeviceId();

Tags & Segmentation​

Tags
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​

Language
await AppPushService.user.setLanguage('fr');   // ISO 639-1 code

Aliases & Email​

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​

Opt-in / Opt-out
await AppPushService.user.optOut();
await AppPushService.user.optIn();
const optedIn = await AppPushService.user.getOptedIn();

Foreground Display​

Platform Difference

preventDefault() works only on Android. On iOS, notifications display synchronously before JavaScript executes.

Foreground Display (Android)
AppPushService.onNotificationWillDisplay(({ notification, preventDefault }) => {
// Call synchronously — the SDK is waiting on this handler.
// Call preventDefault() to suppress the notification.
preventDefault();
});

Badge (Optional)​

Platform Difference

iOS uses the native badge API. Android uses launcher broadcasts (Samsung, MIUI, ASUS only).

Badge
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.

Silent Push
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)​

Dismiss Notifications
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:

Silent pushes on Android

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​

ProblemCauseFix
Token never arrives (Android)Firebase not configuredPlace google-services.json in android/app/
Token never arrives (iOS)Push capability missingAdd Push Notifications via Signing & Capabilities
FIS_AUTH_ERROR in Logcat (Android)Firebase API key rejected for this buildFollow FIS_AUTH_ERROR
Token never arrives (Android); Logcat shows c2dm: [-19,ERR_SERVICE_NOT_AVAILABLE,0,0]; onError gives tokenRegistrationFailedThe 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 calledCall after initialize()
No push in background (Android)notification block in FCM payloadSend data-only payload for full SDK control
Silent push shown as a notification (Android)silent key missing from dataAdd "silent": "true" to the data payload
onSilentNotification never fires (iOS)Background Modes → Remote notifications missing, or payload has an alertEnable the capability and send only content-available: 1
Cannot find modulePackage not installedRun npm install and npx pod-install
Swift runtime error (ObjC project)Missing Swift stdlibAdd 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-colourFollow Notification Icon & Color
iOS images don't showNo NSE, or mutable-content missingSet up the NSE and send mutable-content: 1
NSE never runsNSE deployment target is higher than the device's iOSLower the NSE's Minimum Deployments to your app's
pod install: object version 70Xcode 16 synchronized folderRight-click the extension folder → Convert to Group
pod install still installs an older AppsOnAir-AppPush after upgradingPodfile.lock is pinning itRun pod update AppsOnAir-AppPush AppsOnAir-AppPush-ServiceExt
pod install: "Unable to find a specification for AppsOnAir-AppPush-ServiceExt"Local spec index is out of dateRun pod install --repo-update
Archive: "Multiple commands produce AppsOnAir_AppPush.framework"Extension uses the deprecated AppsOnAir-AppPush/ServiceExtension subspecSwitch to the AppsOnAir-AppPush-ServiceExt pod and update the import (see the note in the NSE section)
NCE not shown on long-pressaps.category doesn't match UNNotificationExtensionCategorySend the same category string
Doesn't work in Expo GoNative modules and extensions need a native buildUse a development build

Setup Checklist​

Android

  • google-services.json is in android/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 in AndroidManifest.xml
  • A white-on-transparent icon is in res/drawable*, and the color is in res/values/colors.xml

iOS

  • AppsonairAppId is in Info.plist, and pod install has been run
  • Push Notifications and Background Modes → Remote notifications are enabled
  • NSE: target added (deployment target matches the app), AppsOnAir-AppPush-ServiceExt pod in the Podfile, AppsOnAirNotificationServiceExtension subclass, same App Group on app and NSE
  • NCE (optional): target added, AppsOnAir-AppPush-ContentExt pod in the Podfile, storyboard removed, category set
  • Pushes send mutable-content: 1 (and aps.category for the NCE)

JavaScript

  • AppPushService.initialize() runs at startup
  • requestPermission() is called

Log Levels​

Set before initialize():

Log Level
await AppPushService.debug.setLogLevel('verbose');   // before initialize()
await AppPushService.initialize({ debug: __DEV__ });

Available levels: none, fatal, error, warn, info, debug, verbose.