【问题标题】:Ionic notification in androidandroid中的离子通知
【发布时间】:2016-12-22 05:41:09
【问题描述】:

我使用 Blow 代码进行离子通知我使用了 fcm(firebase 云消息传递)

当应用程序关闭时我收到推送通知,但当应用程序在 android 中打开(运行)时我没有收到通知

app.js

.config(function($ionicCloudProvider) {
    $ionicCloudProvider.init({
    "core": {
      "app_id": "xxxxxx"
    },
    "push": {
      "sender_id": "xxxxxxxxxxxx",
      "pluginConfig": {
        "ios": {
          "badge": true,
          "sound": true
        },
        "android": {
            "badge": true,
          "iconColor": "#343434"
        }
      }
    }
  });

})

controler.js

$ionicPush.register().then(function(t) {
            return $ionicPush.saveToken(t);
          }).then(function(t) {
            console.log('Token saved:', t.token);
            alert(t.token);
          });

$rootScope.$on('cloud:push:notification', function(data) {
    console.log("dbhfd")
        var msg = data.message;
    console.log("dbhfd")
        alert(msg.title + ': ' + msg.text);
        $state.go('message');
});

【问题讨论】:

    标签: android angularjs ionic-framework push-notification


    【解决方案1】:

    在前台收到新通知时使用本地通知

        this.fcm.onNotification().subscribe(data => {
          if(data.wasTapped){
            console.log("Received in background");
          } else {
            console.log("Received in foreground");
              this.localNotifications.schedule({
               id: 1,
               title: ""+data.title+"",
               text: ""+data.body+""
            });
          };
        });
    

    【讨论】:

      【解决方案2】:

      嗨, 当应用程序打开时,即使您可以使用 Facebook 或任何其他应用程序进行检查,您也不会收到任何通知。如果应用程序关闭,那么只有您会收到通知,这不是问题,我认为您已经实现了目标

      【讨论】:

      • 这不是真的。甚至 Facebook 应用程序在打开时也会收到通知。它们不会显示在状态栏中,但实际上会在您在应用程序的标题中获得徽章时收到。通知是让应用响应新内容的完美方式,无需每隔几秒/分钟轮询一次新内容。
      • 实际上我正在使用聊天应用程序。应用打开时如何更新ui?
      • cloud:push:notification 方法未触发。
      • @Sakshi 我对 Ionic Push 不熟悉,但我使用 cordova-plugin-fcm 并且能够通过前台的应用程序获得通知。看看github.com/fechanique/cordova-plugin-fcm,header 接收推送通知数据
      • @JanP 我已经安装了 app.js:48 Uncaught ReferenceError: FCMPlugin is not defined 但出现错误 Uncaught ReferenceError: FCMPlugin is not defined。
      【解决方案3】:

      如果您想与 firebase + 推送通知集成,则可以点击此链接 here! 在这个推送通知链接中,只需在 App.tsx 中保留 register() 函数和相关代码,您将获得前台和后台通知。

      如果您想生成本地通知,请点击此链接here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-05
        • 2023-03-08
        • 1970-01-01
        • 2016-08-12
        • 1970-01-01
        相关资源
        最近更新 更多