带有 nodejs 的 FCM 不向模拟器发送通知

时间:2021-03-20 18:57:34

标签: node.js firebase firebase-cloud-messaging

我正在尝试使用 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);
    });

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

0 个答案:

没有答案
相关问题