https://github.com/onesignal/onesignal-expo-plugin
The OneSignal Expo plugin allows you to use OneSignal without leaving the managed workflow. Developed in collaboration with SweetGreen.
https://github.com/onesignal/onesignal-expo-plugin
android eas expo ios notifications onesignal onesignal-notifications push push-notifications react-native
Last synced: 5 days ago
JSON representation
The OneSignal Expo plugin allows you to use OneSignal without leaving the managed workflow. Developed in collaboration with SweetGreen.
- Host: GitHub
- URL: https://github.com/onesignal/onesignal-expo-plugin
- Owner: OneSignal
- License: other
- Created: 2021-08-12T19:04:44.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-05-13T18:43:10.000Z (about 1 year ago)
- Last Synced: 2025-05-15T10:02:22.141Z (about 1 year ago)
- Topics: android, eas, expo, ios, notifications, onesignal, onesignal-notifications, push, push-notifications, react-native
- Language: TypeScript
- Homepage:
- Size: 1.53 MB
- Stars: 170
- Watchers: 34
- Forks: 61
- Open Issues: 26
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Support: support/FileManager.ts
Awesome Lists containing this project
README
Welcome to the onesignal-expo-plugin 👋
> The OneSignal Expo plugin allows you to use OneSignal without leaving the managed workflow. Developed in collaboration with SweetGreen.
- 🏠 [Homepage](https://github.com/OneSignal/onesignal-expo-plugin#readme)
- 🖤 [npm](https://www.npmjs.com/package/onesignal-expo-plugin)
## Overview
This plugin is an [Expo Config Plugin](https://docs.expo.dev/guides/config-plugins/). It extends the Expo config to allow customizing the prebuild phase of managed workflow builds (no need to eject to a bare workflow). For the purposes of OneSignal integration, the plugin facilitates automatically generating/configuring the necessary native code files needed to get the [OneSignal React-Native SDK](https://github.com/OneSignal/react-native-onesignal) to work. You can think of adding a plugin as adding custom native code.
## Supported environments:
- [The Expo run commands](https://docs.expo.dev/workflow/customizing/) (`expo run:[android|ios]`)
- [Custom clients](https://blog.expo.dev/introducing-custom-development-clients-5a2c79a9ddf8)
- [EAS Build](https://docs.expo.dev/build/introduction/)
---
## Install
See the [Setup Guide](https://documentation.onesignal.com/docs/en/react-native-expo-sdk-setup) for setup instructions.
## Configuration in app.json / app.config.js
### Plugin
Add the plugin to the **front** of the [plugin array](https://docs.expo.dev/versions/latest/config/app/). It should be added automatically if you ran `npx expo install`. Just make sure it is the first plugin in the array and to configure any desired plugin props:
**app.json**
```json
{
"plugins": [
[
"onesignal-expo-plugin",
{
"mode": "development"
}
]
]
}
```
or
**app.config.js/ts**
```js
import withOneSignal from 'onesignal-expo-plugin/plugin';
export default {
...
plugins: [
withOneSignal({
mode: 'development',
}),
],
};
```
#### Plugin Prop
You can pass props to the plugin config object to configure:
| Plugin Prop | | |
| ------------------------ | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `mode` | **required** | Used to configure [APNs environment](https://developer.apple.com/documentation/bundleresources/entitlements/aps-environment) entitlement. `"development"` or `"production"` |
| `devTeam` | **deprecated** | Use [`ios.appleTeamId`](https://docs.expo.dev/versions/latest/config/app/#appleteamid) in your Expo config instead. Falls back to this value if `appleTeamId` is not set. e.g: `"91SW8A37CR"` |
| `iPhoneDeploymentTarget` | optional | Target `IPHONEOS_DEPLOYMENT_TARGET` value to be used when adding the iOS [NSE](https://documentation.onesignal.com/docs/service-extensions). A deployment target is nothing more than the minimum version of the operating system the application can run on. This value should match the value in your Podfile e.g: `"12.0"`. |
| `smallIcons` | optional | An array of local paths to small notification icons for Android. Image should be white, transparent, and 96x96 in size. Input images will be automatically scaled down and placed in the appropriate resource folders. e.g: `["./assets/ic_stat_onesignal_default.png"]`. See https://documentation.onesignal.com/docs/customize-notification-icons#small-notification-icons. |
| `largeIcons` | optional | An array of local paths to large notification icons for Android. Image should be white, transparent, and 256x256 in size. e.g: `["./assets/ic_onesignal_large_icon_default.png"]`. See https://documentation.onesignal.com/docs/customize-notification-icons#large-notification-icons. |
| `smallIconAccentColor` | optional | The accent color to use for notification icons on Android. Must be a valid hex value, e.g: `"#FF0000"` |
| `iosNSEFilePath` | optional | The local path to a custom Notification Service Extension (NSE), written in Swift. The NSE will typically start as a copy of the [default NSE](https://github.com/OneSignal/onesignal-expo-plugin/blob/main/serviceExtensionFiles/NotificationService.swift), then altered to support any custom logic required. e.g: `"./assets/NotificationService.swift"`. |
| `appGroupName` | optional | Used to configure a custom iOS [App Group](https://documentation.onesignal.com/docs/ios-sdk-setup#step-3-create-an-app-group) name. If not provided, defaults to `"group.{ios.bundleIdentifier}.onesignal"`. e.g: `"group.com.example.myapp.onesignal2"`. |
| `nseBundleIdentifier` | optional | Used to configure a custom bundle identifier suffix for the iOS Notification Service Extension. The full bundle identifier will be `"{ios.bundleIdentifier}.{nseBundleIdentifier}"`. If not provided, defaults to `"OneSignalNotificationServiceExtension"`. |
| `disableNSE` | optional | If `true`, the iOS Notification Service Extension (NSE) will not be added to the project. The NSE is required for badges, confirmed delivery, media attachments, and action buttons. Only disable this if you only need basic push notifications. |
| `disableLocation` | optional | If `true`, the native OneSignal location module will be excluded from iOS and Android builds. Use this if your app does not call `OneSignal.Location` and should not link native location APIs. |
| `sounds` | optional | An array of local paths to custom notification sound files (`.wav` only, ≤30 seconds). Files are copied into the app bundle on iOS and `res/raw/` on Android. e.g: `["./assets/notification_sound.wav"]`. See https://documentation.onesignal.com/docs/customize-notification-sounds. |
| `liveActivities` | optional | Opt in to scaffolding an iOS Widget Extension target for OneSignal Live Activities. Use `{}` for the default `OneSignalWidget` target, or pass `targetName`, `bundleIdentifierSuffix`, `widgetFilePath`, or `deploymentTarget` to customize it. See [Live Activities](#live-activities). |
### Disabling Location
When `disableLocation` is enabled, the plugin configures native dependency
resolution so `react-native-onesignal` excludes the location module. On iOS, it
writes the Podfile environment setting used during CocoaPods resolution. On
Android, it writes `onesignal.disableLocation=true` to the generated Gradle
properties.
### Live Activities
Set `liveActivities` to an object to add the native iOS Widget Extension files and Podfile target required for OneSignal Live Activities.
```json
{
"plugins": [
[
"onesignal-expo-plugin",
{
"mode": "development",
"liveActivities": {}
}
]
]
}
```
The default widget target is `OneSignalWidget`, with a bundle identifier of `"{ios.bundleIdentifier}.OneSignalWidget"`. You can customize it:
```json
{
"liveActivities": {
"targetName": "MyWidget",
"bundleIdentifierSuffix": "widget",
"widgetFilePath": "./widgets/MyWidgetLiveActivity.swift",
"deploymentTarget": "16.2"
}
}
```
The default generated widget uses OneSignal's `DefaultLiveActivityAttributes`, so call `setupDefault()` from your app code after initializing OneSignal:
```js
import { OneSignal } from 'react-native-onesignal';
OneSignal.initialize('YOUR-ONESIGNAL-APP-ID');
OneSignal.LiveActivities.setupDefault();
```
Requirements:
- iOS 16.2+ for the generated widget target.
- A `.p8` APNs key. Apple does not support p12 certificates for Live Activities.
- `OneSignal.LiveActivities.setupDefault()` must be called before using OneSignal's Live Activity APIs.
- The widget target depends on `OneSignalXCFramework`, which mirrors the [Cross-platform Live Activity setup](https://documentation.onesignal.com/docs/cross-platform-live-activity-setup#3-add-the-onesignalxcframework-to-your-podfile) and avoids the React Native + `use_frameworks!` host/extension linkage conflict.
See the [Cross-platform Live Activity SDK setup](https://documentation.onesignal.com/docs/cross-platform-live-activity-setup) and [Live Activities developer setup](https://documentation.onesignal.com/docs/live-activities-developer-setup) for API usage and customization.
### OneSignal App ID
Add your OneSignal App ID to your [Expo constants via the `extra` param](https://docs.expo.dev/versions/latest/config/app/#extra):
**Example:**
```json
{
"extra": {
"oneSignalAppId": ""
}
}
```
You can then access the value to pass to the `initialize` function:
```js
import { OneSignal } from 'react-native-onesignal';
import Constants from 'expo-constants';
OneSignal.initialize(Constants.expoConfig.extra.oneSignalAppId);
```
Alternatively, pass the app ID directly to the function:
```js
OneSignal.initialize('YOUR-ONESIGNAL-APP-ID');
```
### Versioning
In your configuration file, make sure you set:
| Property | Details |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `version` | Your app version. Corresponds to `CFBundleShortVersionString` on iOS. It is a human-readable version number of an iOS app, and is typically in the format of "X.X.X" (e.g. "1.0" or "2.3.1"). It is the version number that is typically displayed to users in the App Store and in the app itself. This value will be used in your NSE\* target's plist file. |
| `ios.buildNumber` | Build number for your iOS standalone app. Corresponds to `CFBundleVersion` and must match Apple's specified format (e.g: "42" or "100"). The build number is used by the App Store and iOS to identify and track different versions of an app, and is typically incremented for each new release. It is a number typically used for the developer's and system reference. This value will be used in your NSE\* target's plist file. |
| `ios.bundleIdentifier` | Bundle identifier for your iOS standalone app. Corresponds to `CFBundleIdentifier`. It's a unique identifier string that is used to identify an iOS app or bundle. It is typically in the format of `"com.companyname.appname"` (e.g. `"com.example.myapp"`). This value will be used in your NSE\* target's plist and entitlements file. |
\* NSE = Notification Service Extension. Learn more about the NSE [here](https://documentation.onesignal.com/docs/service-extensions).
## EAS (Expo Application Services)
See our [EAS documentation](EAS.md) for help with EAS.
### iOS Credentials: OneSignal + EAS
To distribute your iOS application via EAS, you will need to ensure your credentials are set up correctly. See our [credentials setup guide for instructions](IOS_CREDENTIALS_EAS.md).
## Prebuild (optional)
Prebuilding in Expo will result in the generation of the native runtime code for the project (and `ios` and `android` directories being built). By prebuilding, we automatically link and configure the native modules that have implemented CocoaPods, autolinking, and other config plugins. You can think of prebuild like a native code bundler.
When you run `expo prebuild` we enter into a custom managed workflow which provides most of the benefits of bare workflows and managed workflows at the same time.
#### Why should I prebuild?
It may make sense to prebuild locally to inspect config plugin changes and help in debugging issues.
#### Run
```sh
npx expo prebuild
```
```sh
# nukes changes and rebuilds
npx expo prebuild --clean
```
**EAS Note:** if you choose to stay in a fully managed workflow by not prebuilding, EAS will still run `npx expo prebuild` at build time. You can also prebuild locally but remain in a fully managed workflow by adding the `android` and `ios` directories to your .gitignore.
## Run
The following commands will prebuild _and_ run your application. Note that for iOS, push notifications will **not** work in the Simulator.
```sh
# Build and run your native iOS project
npx expo run:ios
# Build and run your native Android project
npx expo run:android
```
---
## 🤝 Contributing
Contributions, issues and feature requests are welcome!
Feel free to check [issues page](https://github.com/OneSignal/onesignal-expo-plugin/issues).
## Show your support
Give a ⭐️ if this project helped you!
## OneSignal
- Website: https://onesignal.com
- Twitter: [@onesignal](https://twitter.com/onesignal)
- Github: [@OneSignal](https://github.com/OneSignal)
- LinkedIn: [@onesignal](https://linkedin.com/company/onesignal)
## 📝 License
Copyright © 2023 [OneSignal](https://github.com/OneSignal).
This project is [MIT](https://github.com/OneSignal/onesignal-expo-plugin/blob/main/LICENSE) licensed.