首页 > 解决方案 > Firebase 云功能错误:已超过截止日期(Flutter 推送通知)

问题描述

因此,我正在尝试使用 Firebase-cloud-functions 在我的 Flutter 应用程序中实现自动推送通知功能。

我在 Firebase 控制台中收到此错误:

Error: Deadline exceeded
    at Http2CallStream.call.on (/srv/node_modules/@grpc/grpc-js/build/src/call.js:68:41)
    at emitOne (events.js:121:20)
    at Http2CallStream.emit (events.js:211:7)
    at process.nextTick (/srv/node_modules/@grpc/grpc-js/build/src/call-stream.js:71:22)
    at _combinedTickCallback (internal/process/next_tick.js:132:7)
    at process._tickDomainCallback (internal/process/next_tick.js:219:9)

这是我的 Firebase 函数的 index.js:

const functions = require('firebase-functions');
const admin = require('firebase-admin');

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

var msgData

exports.offerTrigger = functions.firestore.document(
    'message/{messageID}'
).onCreate((snapshot, context) => {
    msgData = snapshot.data();

    admin.firestore().collection('pushtokens').get().then(async (snapshots) => {
        var tokens = [];
        if (snapshots.empty) {
            console.log('No Devies');
        } else {
            for (var token of snapshots.docs) {
                tokens.push(token.data().devtoken);
            }

            var payload = {
                "notification": {
                    "title": msgData.buissnessName,
                    "body": msgData.messageValue,
                    "sound": "default"
                },
                "data": {
                    "sendername": msgData.buissnessName,
                    "message": msgData.messageValue,
                }
            }
            try {
                const response = await admin.messaging().sendToDevice(tokens, payload);
                console.log('Pushed them all');
            }
            catch (err) {
                console.log(err);
            }
        }
    })
})

这就是令牌在 Firestore 中保存的方式:

在此处输入图像描述

这就是我尝试发送推送通知的方式。但是没有一个用户收到它。

在此处输入图像描述

标签: node.jsfirebasegoogle-cloud-firestorefirebase-cloud-messaginggoogle-cloud-functions

解决方案


推荐阅读