Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Uriel_S_
Beginner
121 Views

How to use onesignal ? put that in index.html

 

 

Hello, I have a problem with onesignal.
Just do not know what to index.html to receive notification.

onesignal this so  > estou.png

 

in that part of APP that put the codes to receive a message?

I'm a beginner.

Tags (2)
0 Kudos
5 Replies
Chris_P_Intel
Employee
121 Views

Do you know Javascript? The OneSignal Cordova plugin (or their RESTful API) are going to require quite a bit of Javascript skill to leverage in your app.

 

Uriel_S_
Beginner
121 Views

I am new to Javascript.
But it's just a test.
Do you want something to appear.

 

My app is simple, a screen with 1 text.

Hugs. 

Thomas_B_6
New Contributor I
121 Views

Hi Uriel,

the onsignal setup is quite straight forward.

Just check the Javascript examples.

1. Install the Javascript SDK (Google for Onesignal and XDK)

2. Create a simple xdk page with just on button in editor (btn_push)

3. insert the following Javascript into your js.file

4. Dont forget to prepare the Google ID and the Onesignal ID

 

Best,

Tom

(function () {
    "use strict";
    /*
      hook up event handlers 
    */
    function register_event_handlers() {

        // window.plugins.OneSignal.setLogLevel({logLevel: 4, visualLevel: 4});

        var notificationOpenedCallback = function (jsonData) {

            alert("Message was \n" + jsonData.message);
        };


        window.plugins.OneSignal.init("xxxxx-xxxxx-xxxxx-xxxxx-xxxxx", {
                googleProjectNumber: "xxxxxxxxx"
            },
            notificationOpenedCallback);

 

        // Show an alert box if a notification comes in when the user is in your app.
        //    window.plugins.OneSignal.enableInAppAlertNotification(true);

        /* button  #btn_push */
        $(document).on("click", "#btn_push", function (evt) {

            window.plugins.OneSignal.sendTag("Group", "My Testgroup");
          //  alert("Registered");

            window.plugins.OneSignal.getIds(function (ids) {
                alert("ID : "+ids.userId + "\nToken "+  ids.pushToken);
            });


        });

    }
    document.addEventListener("app.Ready", register_event_handlers, false);
})();

Uriel_S_
Beginner
121 Views

 

Does not work. Please look at my code in the pastebin.

 

 App.js > http://pastebin.com/RW67UCXH  end index.html  > http://pastebin.com/11CD0eKN

 

 
  <!-- cordova-plugin-statusbar Yes -->
  <!-- cordova-plugin-device Yes -->
  <!-- cordova-plugin-splashscreen Yes -->
  <!-- onesignal-cordova-plugin-pgb-compat Yes-->
  <!-- com.google.playservices Yes -->
  <!-- Minimum Android API 14 -->
  <!-- Target Android API 19 -->

 

Hugs 

Uriel_S_
Beginner
121 Views

Yes. 

 

Very good 

Reply