首页 > 解决方案 > 带有nodejs的FCM未向模拟器发送通知

问题描述

我试图使用 firebase admin 向我的所有设备发送通知,但它不起作用

import admin from 'firebase-admin';

var serviceAccount = require('./firebase.json');

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
});

 var condition = "!('stock-GOOG' in topics)";

  // See documentation on defining a message payload.
  var message = {
    data: {
      title: 'asdasdas',
    },
    notification: {
      title: '$FooCorp up 1.43% on the day',
      body:
        '$FooCorp gained 11.80 points to close at 835.67, up 1.43% on the day.',
    },
    condition: condition,
  };

  // Send a message to devices subscribed to the combination of topics
  // specified by the provided condition.
  admin
    .messaging()
    .send(message)
    .then((response) => {
      // Response is a message ID string.
      console.log('Successfully sent message:', response);
    })
    .catch((error) => {
      console.log('Error sending message:', error);
    });

尽管它让我知道消息已正确发送,但我的模拟器上没有任何内容出现在我正在使用它进行测试的情况下。当我尝试从控制台发送通知时,一切正常。

标签: node.jsfirebasefirebase-cloud-messaging

解决方案


推荐阅读