[英]phonegap-plugin-push do not register
我正在學習如何使用phonegap制作應用程序,並且嘗試從此處使用phonegap推送插件,問題是在初始化它后,不會觸發register事件,我執行了以下步驟
phonegap plugin add phonegap-plugin-push --variable SENDER_ID="XXXXXXX"
安裝了插件phonegap plugin add phonegap-plugin-push --variable SENDER_ID="XXXXXXX"
phonegap build android
平台phonegap build android
它添加了android平台,並且沒有向我顯示任何錯誤。 但是當我運行該應用程序時,它確實會觸發注冊事件。 這是我的代碼
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')
}
};
在index.html中,腳本被稱為
<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>
它有什么問題嗎? 我怎么知道插件是否初始化? 或為什么它沒有觸發注冊事件。
放
// 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')
內
onDeviceReady: function() {
app.receivedEvent('deviceready');
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.