GithubHelp home page GithubHelp logo

onesignaldevelopers / onesignal-cordova-sample Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 2.0 53 KB

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

License: Other

CSS 48.97% HTML 32.96% JavaScript 18.07%
cordova ionic onesignal onesignal-notifications onesignal-sdk

onesignal-cordova-sample's Introduction

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.