簡體   English   中英

phonegap-plugin-push不注冊

[英]phonegap-plugin-push do not register

我正在學習如何使用phonegap制作應用程序,並且嘗試從此處使用phonegap推送插件,問題是在初始化它后,不會觸發register事件,我執行了以下步驟

  • 用phonegap創建項目
  • 按照說明使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM