仅在前景中使用FCM

时间:2019-03-14 10:05:29

标签: javascript firebase firebase-cloud-messaging

只有在应用程序处于前台时才可以显示通知吗?我不需要在后台显示通知。 我的setBackgroundMessageHandler在服务人员中看起来像:

messaging.setBackgroundMessageHandler(function(payload) {
    console.log('[firebase-messaging-sw.js] Received background message ', payload);
    // Customize notification here
    var notificationTitle = 'Background Message Title';
    var notificationOptions = {
        body: 'Background Message body.',
        icon: '/firebase-logo.png'
    };

});

我没有返回showNotification,但正在显示

1 个答案:

答案 0 :(得分:0)

Firebase Cloud Messaging有两种类型的消息:

  1. 通知。当应用程序处于后台时,这些由系统处理,并在这种情况下显示在系统抽屉中。当您的应用程序位于前台时,通知会传递到您的应用程序代码。
  2. 数据消息。无论应用程序是在前台还是在后台,这些内容始终会传递到您的应用程序代码中。

由于要防止系统在系统托盘中显示通知,因此应发送数据消息。

相关问题