Ionic应用程序在后台时不接收推送通知

时间:2019-10-05 18:01:09

标签: ionic-framework firebase-cloud-messaging

在这里快速提问。

我开发了一个使用Firebase接收通知的Ionic / Cordova应用程序。 这是我在另一个应用程序中发送的消息:

        JsonObject jNotification = new JsonObject();
        jNotification.addProperty("title", title);
        jNotification.addProperty("body", body);

        JsonObject jMessage = new JsonObject();
        jMessage.add("notification", jNotification);
        jMessage.addProperty("topic", topic);

        JsonObject jData = new JsonObject();
        jData.addProperty("title", title);
        jData.addProperty("body", body);
        jData.addProperty("sound", "default");
        jData.addProperty("click_action", "FCM_PLUGIN_ACTIVITY");
        jData.addProperty("icon", "fcm_push_icon");
        jData.addProperty("priority", "high");
        jMessage.add("data", jData);

        JsonObject jFcm = new JsonObject();
        jFcm.add("message", jMessage);

这被发送到URL

  

https://fcm.googleapis.com/v1/projects/PROJECT/messages:send

此后,我可以通过service-account.json获取访问令牌。

移动应用程序通过以下方式接收推送:

      if (this.platform.is('cordova')) {

        this.fcm.subscribeToTopic('TOPIC');


            this.fcm.getToken().then(token => {
              // save this server-side and use it to push notifications to this device
              console.log(`Obtained token: ${token}`);
            });

            this.fcm.onTokenRefresh().subscribe(token => {
              // save this server-side and use it to push notifications to this device
              console.log(`Obtained refreshed token: ${token}`);
            });

            this.fcm.onNotification().subscribe(data => {
              if (data.wasTapped) {
                console.log(Notification received`);
          } else {
            this.dialogs.alert(data.body, data.title)
              .then(() => console.log('Dialog dismissed'))
              .catch(e => console.log('Error displaying dialog', e));

          }
        })
      }

在应用程序中时,通过其他应用程序甚至使用Firebase控制台都不会出现问题。 但是,在应用程序外部时,推送通知不会在系统任务栏中弹出。

0 个答案:

没有答案
相关问题