Skip to content

This is a sample app showing how to use Cordova with OneSignal in an Android application.

License

Notifications You must be signed in to change notification settings

OneSignalDevelopers/OneSignal-Cordova-Sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OneSignal Cordova Example

An example Cordova app with the OneSignal plugin intergated showing how to use each of its functions.

Trying the Example Out!

  1. To build the example first run cordova platform add android and/or cordova platform add ios.
  2. Open www\js\index.js and replace "8d5e7b7f-9b51-476e-93f9-2edb0d332e4a" with your OneSignal App Id.
  3. Build and run the app on your device with cordova run android or cordova run ios.

Installing in Your Own Project

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.

Setup Cordova-OneSignal < 3.0.0

Take a look to the old-version branch of this repo

Step Cordova 2.x to 3.0.0 Upgrade Guide

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.

  1. Open your main file (e.g: index.js)
  2. 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");

Setup OneSignal-Cordova version 3.0.0 or greather

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:

  1. Open your config.xml file located in your root folder
  2. Add the following line after <platform></platform> tags
<preference name="AndroidXEnabled" value="true" />

Using Ionic instead?