0

I am trying for days now to get a basic application with push notification running.

I am using PhoneGap Build (Desktop App) and am testing on a Android Device. I tried various tutorials but they never seem to work. Running the following code just gives no reaction at all.

This is my current code:

config.xml I added the following lines:

<preference name="android-build-tool" value="gradle" />
<plugin name="phonegap-plugin-push" source="npm">
    <param name="SENDER_ID" value="540732047871" />
</plugin>

index.html

<body>  
    <div class="app">
        <h1>PhoneGap</h1>
    </div>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
        app.initialize();
    </script>
</body>

index.js

var app = {
// Application Constructor
initialize: function() {
    this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
    document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
    var push = PushNotification.init({
        "android": {
            "senderID": "540732047871"
        },
        "ios": {"alert": "true", "badge": "true", "sound": "true"}, 
        "windows": {} 
    });

    push.on('registration', function(data) {
        console.log("registration event");
        document.getElementById("regId").innerHTML = data.registrationId;
        console.log(JSON.stringify(data));
    });

    push.on('notification', function(data) {
        console.log("notification event");
        console.log(JSON.stringify(data));
        var cards = document.getElementById("cards");
        var card = '<div class="row">' +
              '<div class="col s12 m6">' +
              '  <div class="card darken-1">' +
              '    <div class="card-content black-text">' +
              '      <span class="card-title black-text">' + data.title + '</span>' +
              '      <p>' + data.message + '</p>' +
              '    </div>' +
              '  </div>' +
              ' </div>' +
              '</div>';
        cards.innerHTML += card;

        push.finish(function () {
            console.log('finish successfully called');
        });
    });

    push.on('error', function(e) {
        console.log("push error");
    });
}};

Am I doing something wrong? I'm using code based on the "github"-page of the "phonegap-plugin-push". Any ideas what I seem to have missed in creating the project?

Sven Ya
  • 552
  • 1
  • 5
  • 12

1 Answers1

0

@Sven,

Canned Message
I am blogging this tomorrow, so i don't have to repeat this answer again and again.

You cannot use Phonegap Desktop App with Phonegap Build.

Phonegap Desktop App uses Phonegap CLI, so if you want to use Phonegap Desktop App you need to stay with Phonegap CLI.

If you want to use Phonegap Build, then forget what you have done and start over OR make Minor modifications to move Phonegap Desktop App to Phonegap Build. To be clear, the difference is minor, but enough to keep tripping you.

Also, you will not be able to use Phonegap Developer App as that is meant to work with Phonegap Desktop App. You cannot use either CLI or Build with Developer App.

FWIW: The documentation is the issue. I've been trying to get Phonegap to fix this. Here is the report on the issue.

Let me know what you want to do.

Jesse

  • Oh okay, didn'T read that anywhere. Thanks for that. I will try to get it qorking with PhoneGap Build then. Maybe that fixes the issue. I'll be commenting what I've found. – Sven Ya Mar 22 '16 at 12:30
  • @Sven, it is written in the documentation, but not **very well**. –  Mar 22 '16 at 20:55