简体   繁体   English

phonegap-plugin-push不注册

[英]phonegap-plugin-push do not register

I'm learning on how to make app using phonegap and i'm trying to use phonegap push plugin from here the issue is that after i initialize it the register event do not fire, i made this steps 我正在学习如何使用phonegap制作应用程序,并且尝试从此处使用phonegap推送插件,问题是在初始化它后,不会触发register事件,我执行了以下步骤

  • create the project with phonegap 用phonegap创建项目
  • installed the plugin following the instructions using phonegap plugin add phonegap-plugin-push --variable SENDER_ID="XXXXXXX" 按照说明使用phonegap plugin add phonegap-plugin-push --variable SENDER_ID="XXXXXXX"安装了插件phonegap plugin add phonegap-plugin-push --variable SENDER_ID="XXXXXXX"
  • the build the platform with phonegap build android phonegap build android平台phonegap build android

it added android platform and didt not show me any error. 它添加了android平台,并且没有向我显示任何错误。 but when i run the app it doents fire the registration event. 但是当我运行该应用程序时,它确实会触发注册事件。 This is my 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 the index.html the script are called this way 在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>

its there something wrong? 它有什么问题吗? how do i know if the plugin its initializating? 我怎么知道插件是否初始化? or why it isnt triggered the registration event. 或为什么它没有触发注册事件。

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')

inside

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

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM