Google云消息传递推送通知:PushNotification

时间:2017-03-01 01:48:02

标签: android cordova ionic-framework push-notification google-cloud-messaging

我正在使用Visual Studio使用Google Cloud Messaging推送通知开发离子应用程序。首先,我从https://github.com/phonegap/phonegap-plugin-push添加phonegap-plugin-push,然后从Google Cloud Messaging API插入我的senderID,即项目编号。接下来,我添加以下代码。

      var push = PushNotification.init({
         "android" : {
          "senderID" : "9XX5XXX346XX"// This is your project number which you've created on Google Developers Console
         },
         "ios" : {},
         "windows" : {}
        });

   push.on('registration', function(data) {
    //data.registrationId
    //send this token on server

   });
   push.on('notification', function(data) {
    if (data.sound) {// play specific sound on notification received(When app running)
     var snd = new Media('file:///android_asset/www/sound/' + data.sound);
     snd.play();
    }

    if (!data.additionalData.foreground) {
     // app is NOT RUNNING and new notification is RECEIVED

    } else {
     // app is RUNNING and new notification is RECEIVED
    }
   });

   push.on('error', function(e) {
    //alert(JSON.stringify(data))
    // e.message
   });

当我在模拟器和Android设备中运行我的应用程序时。它带有eror PushNotification.init。我可以知道为什么吗?

0 个答案:

没有答案