This is a simple Ionic React Android app that illustrates how to integrate the OneSignal SDK.
Running on Cordova onesignal-cordova-plugin 3.0.0-beta1 release.
-
Create a simple Ionic app through command line or by visiting Ionic's website.
ionic start -
Choose React as your framework. Ionic React comes with Capacitor.
-
Add your desire platform to the project, for this app I choose Android by running:
ionic capacitor add android -
Install onesignal cordova plugin inside project
npm install onesignal-cordova-plugin -
Build your Android app. This command will open the Android build in Android Studio
ionic capacitor build android -
After building your Ionic applications into a new Android app, run the
cap synccommand (1 time only):npx cap sync -
Add intialization code to
the App.tsxfile (note that this example app has upgraded from Cordova 2.x.x to 3.x.x and temporarily needs to use(window as any).plugins.OneSignal.setAppId(YOUR_APP_ID)). More context here. -
Build again and open project in Android Studio
ionic capacitor build android
Note: Everytime you make a change in the application and you want to see the changes in your Android application, you will have to build your application and re-run it.
- Run your app with the Android emulator or with your Android physical device. Once your application has opened, your device will be registered as a new player inside of the OneSingal application. Make sure your deviced registered by checking your Audience inside of the OneSignal dashboard.