【问题标题】:Error sending notification through firebase function flutter通过firebase函数flutter发送通知时出错
【发布时间】:2021-10-07 01:26:57
【问题描述】:
  • 每当新事件添加到 firebase 的 firestore 时,我都会尝试向用户发送推送通知。
  • 每当我这样做时,它都会返回错误消息Error sending notification
  • node.js
const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp(functions.config().functions);

var newData;

exports.messageTrigger = functions.firestore.document('Messages/{messageId}').onCreate(async(snapshot, context)=> {
    if(snapshot.empty){
        console.log('No Devices');
        return;
    }
    var tokens = ['mobile-token'];

    newData = snapshot.data();

    var payload = {
        notification : {title: 'Push Title', body: 'Push body', sound: 'default'}, 
        data: {click_action: 'FLUTTER_NOTIFICATION_CLICK', message: newData.message},
    };
    try{
        const response = await admin.messaging.sendToDevice(tokens, payload);
        console.log('Notification sent successfully');
    } catch (err) {
        console.log('Error sending notifications');
    }
});
  • 我通过移动令牌代替mobile-token

【问题讨论】:

  • 试试console.log(err)?
  • 我已经用解决方案更新了问题,非常感谢您的建议。

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


【解决方案1】:
  • 解决方案
  • 将admin.messaging.sendToDevice() 更改为 const response = await admin.messaging().sendToDevice(tokens, payload)
  • 因为admin.messaging.sendToDevice() 不是方法

【讨论】:

    猜你喜欢
    • 2017-07-03
    • 2019-09-25
    • 2020-11-20
    • 2019-01-30
    • 2020-08-05
    • 2022-07-29
    • 2019-01-12
    • 2019-11-29
    • 1970-01-01
    相关资源
    最近更新 更多