2016-04-15 7 views
0

Ich lerne auf, wie man app mit phonegap machen und ich versuche, phonegap Push-Plugin von here verwenden das Problem ist, dass, nachdem ich es initiieren das Register Ereignis nicht feuern, ich machte diese Schrittephonegap-plugin-push nicht registrieren

  • das Projekt mit phonegap
  • erstellen Sie das Plugin installiert folgen Sie den Anweisungen unter Verwendung von phonegap plugin add phonegap-plugin-push --variable SENDER_ID="XXXXXXX"
  • die Build die Plattform mit phonegap build android

es Android-Plattform hinzugefügt und didt mir keinen Fehler angezeigt. aber wenn ich die App starte, zünden die Doents das Registrierungsereignis an. Dies ist mein Code

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() { 
    app.receivedEvent('deviceready'); 

}, 
// Update DOM on a Received Event 
receivedEvent: function(id) { 
    var push = PushNotification.init({ 
     "android": { 
      "senderID": "XXXXXXX" 
     }, 
     "ios": {"alert": "true", "badge": "true", "sound": "true"}, 
     "windows": {} 
    }); 
    push.on('registration', function(data) { 
     alert("registration event"); 
     alert(data.registrationId) 
     console.log(JSON.stringify(data)); 
    }); 

    push.on('notification', function(data) { 
     alert("notification event"); 
     console.log(JSON.stringify(data)); 

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

    push.on('error', function(e) { 
     alert("push error"); 
     alert(e); 
    }); 
    alert('hello') 

} 
}; 

in der index.html das Skript so genannt

<script type="text/javascript" src="cordova.js"></script> 
<script type="text/javascript" src="js/push.js"></script> 
<script type="text/javascript" src="js/index.js"></script> 

seine etwas nicht in Ordnung? Woher weiß ich, ob das Plugin initialisiert? oder warum es das Registrierungsereignis nicht ausgelöst hat.

+0

GCM gibt eine Nutzlast. Parsing wird helfen – therealprashant

Antwort

0

Put

// Update DOM on a Received Event 
receivedEvent: function(id) { 
    var push = PushNotification.init({ 
     "android": { 
      "senderID": "XXXXXXX" 
     }, 
     "ios": {"alert": "true", "badge": "true", "sound": "true"}, 
     "windows": {} 
    }); 
push.on('registration', function(data) { 
    alert("registration event"); 
    alert(data.registrationId) 
    console.log(JSON.stringify(data)); 
}); 

push.on('notification', function(data) { 
    alert("notification event"); 
    console.log(JSON.stringify(data)); 

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

push.on('error', function(e) { 
    alert("push error"); 
    alert(e); 
}); 
alert('hello') 

innen

onDeviceReady: function() { 
    app.receivedEvent('deviceready'); 

} 
+0

danke für Ihre Antwort, aber es hat nicht funktioniert. keines der Ereignisse (Registrierung, Benachrichtigung und Fehler) wird aufgerufen –