Ich versuche seit Tagen, eine grundlegende Anwendung mit Push-Benachrichtigung zu erhalten.Empfangen von Push-Benachrichtigungen mit Phonegap Build
Ich verwende PhoneGap Build (Desktop App) und teste es auf einem Android-Gerät. Ich habe verschiedene Tutorials ausprobiert, aber sie scheinen nie zu funktionieren. Das Ausführen des folgenden Codes gibt nur keine Reaktion.
Dies ist mein aktueller Code:
config.xml Ich habe die folgenden Zeilen:
<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");
});
}};
Mache ich etwas falsch? Ich verwende einen Code, der auf der "github" -Seite des "phonegap-plugin-push" basiert. Irgendwelche Ideen, die ich bei der Erstellung des Projekts vermisst zu haben scheint?
Oh okay, habe das nirgendwo gelesen. Dank dafür. Ich werde versuchen, es mit PhoneGap Build dann qorking zu bekommen. Vielleicht behebt das das Problem. Ich werde kommentieren, was ich gefunden habe. –
@Sven, es ist in der Dokumentation geschrieben, aber nicht ** sehr gut **. – JesseMonroy650