【问题标题】:Ionic push notification is not working if app is open如果应用程序打开,离子推送通知不起作用
【发布时间】:2016-09-07 12:05:14
【问题描述】:

当应用程序在后台或屏幕被锁定时,我能够发送推送表单 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);
  });

【问题讨论】:

  • 我也遇到了同样的问题,你找到解决办法了吗?如果你发现了什么,请分享。
  • 不走运,我目前没有在工作。我什么时候工作再告诉你,
  • 也面临同样的问题。 @AnujGupta 你找到什么了吗?
  • @VinothKumar 你试过了吗?

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


【解决方案1】:

在你的 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()
        });

    });

【讨论】:

  • 我在谷歌应用中检查了 GCM,这有效吗?我在那里找到了 FCM,
  • 在 Ionic 项目的哪里添加这段代码?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多