An example Cordova app with the OneSignal plugin intergated showing how to use each of its functions.
- To build the example first run
cordova platform add android
and/orcordova platform add ios
. - Open
www\js\index.js
and replace"8d5e7b7f-9b51-476e-93f9-2edb0d332e4a"
with your OneSignal App Id. - Build and run the app on your device with
cordova run android
orcordova run ios
.
To add the OneSignal to your Cordova project run the following.
cordova plugin add onesignal-cordova-plugin --save
See the OneSignal Cordova SDK Setup Guide for the full installation guide.
Take a look to the old-version branch of this repo
Skip this step if you are already in version 3.0.0 or grather
Take a look to our OneSignal Cordova SDK documentation to learn more about the Cordova 2.x to 3.0.0 upgrade.
- Open your main file (e.g: index.js)
- Replace the following
// OneSignal Initialization
var iosSettings = {};
iosSettings["kOSSettingsKeyAutoPrompt"] = false;
iosSettings["kOSSettingsKeyInAppLaunchURL"] = false;
window.plugins.OneSignal
.startInit("YOUR_ONESIGNAL_APP_ID")
.inFocusDisplaying(window.plugins.OneSignal.OSInFocusDisplayOption.Notification)
.iOSSettings(iosSettings)
.endInit();
With the new initialization:
//OneSignal Initialization
window.plugins.OneSignal.setAppId("YOUR_ONESIGNAL_APP_ID");
window.plugins.OneSignal.setAppId("YOUR_ONESIGNAL_APP_ID");
This sample code is only implented to work with Cordova-Android. Take a look to our OneSignal Cordova SDK documentation to learn more about the iOS setup
If you run into an issue with AndroidXEnabled needing to be true, do the following steps:
- Open your config.xml file located in your root folder
- Add the following line after
<platform></platform>
tags
<preference name="AndroidXEnabled" value="true" />