node.js - 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 中保存的方式:
这就是我尝试发送推送通知的方式。但是没有一个用户收到它。
解决方案
推荐阅读
- reactjs - 您如何称呼酶中的外部功能?
- java - 如何在Java中制作json对象
- java - 基于Java中的给定模式对字符串数组进行排序
- python-3.x - 单击使用烧瓶提交后,如何将文件保存在不同的目录中?
- ios - 在 Swift 4 中使用动画在 UITableView 中添加一行
- php - 从 SQL 转换 time() 以获取每月销售 PHP
- svg-filters - 如何计算线性RGB颜色空间中feComponentTransfer的离散函数中的步骤
- javascript - 使用 Grails 设置 React
- ios - 当动态链接具有自定义子域时,Firebase 动态链接在 iOS 上不起作用
- r - R按错误分组