【发布时间】:2020-09-24 06:53:04
【问题描述】:
每次创建孩子都没有成功时,我都会尝试发送推送通知。 我正在创建一个带有 2 个标记名称的孩子,它们之间有一个问号,并尝试向这些标记发送通知。 从我正在使用的手机中获取令牌
new FirebaseMessaging().getToken().
这里是 firebase 函数代码 `
// // Create and Deploy Your First Cloud Functions
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
// exports.helloWorld = functions.https.onRequest((request, response) => {
// response.send("Hello from Firebase!");
// });
// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');
// The Firebase Admin SDK to access Cloud Firestore.
const admin = require('firebase-admin');
admin.initializeApp();
exports.onNewMessage = functions.database.
ref('/messages/{pushId}')
.onCreate((snapShot,context)=>{
var str = snapShot.key();
var res = str.split("?");
// Notification details.
const payload = {
notification: {
title: 'title!',
body: `body!`,
click_action: 'FLUTTER_NOTIFICATION_CLICK'
}
};
// Send notifications to all tokens.
admin.messaging().sendToDevice(res[0], payload);
admin.messaging().sendToDevice(res[1], payload);
});` .
【问题讨论】:
标签: javascript firebase flutter google-cloud-functions firebase-cloud-messaging