如果应用程序处于打开状态,则离线推送通知无效

时间:2016-09-07 12:05:15

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

我可以发送推送表单apps.ionic.io和邮递员当应用程序在后台或屏幕被锁定但无法在应用程序打开时发送通知。 我的代码是  在运行中

    var io = Ionic.io();
            var push = new Ionic.Push({
               "onNotification": function(notification) {
            alert('Received push notification!');
          },
           "pluginConfig": {
                    "android": {
                        "icon": "ic_stat_icon"
                    }
                },
          "debug": true
        });
 push.register(function(token) {
      console.log("registered");
      console.log("Device token:",token.token);
    });

并在控制器中

 $ionicPush.register( {
    canShowconsole.log: true, //Can pushes show an console.log on your screen?
    canShowAlert: true, //Can pushes show an alert on your screen?
    canSetBadge: true, //Can pushes update app icon badges?
    canPlaySound: true, //Can notifications play a sound?
    canRunActionsOnWake: true, //Can run actions outside the app,
    onNotification: function(notification) {
       console.log(notification);
     // Handle new push notifications here
     alert('Received push notification!');
     return true;
   }
        }).then(function(t) {
    return $ionicPush.saveToken(t);
  }).then(function(t) {
    console.log('Token saved:', t.token);
  });

1 个答案:

答案 0 :(得分:0)

在你的app.js或控制器文件中尝试这个。

$rootScope.$on('cloud:push:notification', function(event, data) {
      var msg = data.message;
      console.log(msg);
      // alert(msg.title + ': ' + msg.text);

      var alertPopup = $ionicPopup.alert({
            title: msg.title,
            template: msg.text.toString()
        });

    });