The React Native OneSignal SDK facilitates the integration of OneSignal's push notification, in-app messaging, email, and SMS services into iOS and Android applications built with React Native. The current stable version is 5.4.3. This library is actively maintained with frequent minor and patch releases, often addressing native SDK updates, bug fixes, and new features like the recent support for React Native's New Architecture (TurboModules) introduced in v5.4.0. Key differentiators include its comprehensive cross-platform support for various notification types and its user-centric APIs for managing user data across channels, distinguishing it from lower-level notification APIs provided by mobile OS platforms.
npm install react-native-onesignalVerified import paths — ran on the pinned version, not inferred.
This quickstart code initializes the OneSignal SDK, sets an external user ID, and registers handlers for incoming notifications (foreground) and notification clicks. It also prompts for push notification permissions on iOS and Android 13+.
For Android: `rm -rf android/app/build android/app/.cxx android/build`. For iOS: `rm -rf ios/build ios/Pods && cd ios && pod install`. Ensure your React Native project is configured for the New Architecture if you intend to use it, or continue with compatibility modes carefully.
Avoid using `LiveActivities.Exit`. If you have existing code relying on this, remove it or find alternative solutions outside the OneSignal SDK for managing Live Activities.
When migrating an existing app, follow the migration advisory from OneSignal. Utilize iOS Phased Rollout and Google Play Staged Rollouts to ensure no unexpected issues. Contact OneSignal support if challenges arise.
Update to `react-native-onesignal@5.4.3` or newer to resolve issues with strict CodeGen rules that might prevent your app from building correctly.
Ensure your project's Kotlin version is compatible with 1.9.25 or is managed correctly to avoid conflicts. Clean Android build caches after updating.
Access the `Notification` object using `notificationReceivedEvent.getNotification()` and then its properties (e.g., `notification.body`). The `notificationReceivedEvent` itself is not the `Notification` object directly.
Update your `react-native` package to a compatible version (e.g., `>=0.76.0`) or downgrade `react-native-onesignal` to a version that supports your current `react-native` version. Check the `package.json` for specific peer dependency ranges.
Navigate to your `ios` directory and run `pod install`. Ensure `OneSignal` is correctly linked in your `Podfile`. Clean your Xcode build folder (`Product > Clean Build Folder`) and delete derived data.
Ensure you are on `react-native-onesignal@5.3.4` or newer. Manually move the `namespace` declaration from `AndroidManifest.xml` to your `app/build.gradle` file, if it still exists there, following modern Android Gradle Plugin conventions.