最初にFCMトークンを生成し、ファイアストアに格納しました。その後、FCMトークンに基づいて通知を送信するクラウド機能を作成しました。ステータスがOKの通知を正常に送信したことを示すクラウド機能を導入しました。しかし、モバイルデバイスには表示されません。私のIndex.jsはクラウド機能を使用してFCMトークンを使用して複数のデバイスにプッシュ通知を送信する方法
'use strict';
const functions = require('firebase-functions');
const Firestore = require('@google-cloud/firestore');
const admin = require('firebase-admin');
const firestore = new Firestore();
const db = admin.firestore();
admin.initializeApp(functions.config().firebase);
exports.hellouser = functions.firestore
.document('users/{token}')
.onWrite(event =>{
var document = event.data.data();
console.log("tokens",document);
var token = ['cdNN0AbYKU0:APA91bEyL0zo3zwHZD8H43Vp7bxAfYgehlVI8LrKktPO2eGuByVDdioysIGxHe5wocwq8ynxRToJPpOve_M59YY_MIRbWLnF9AIgoTwJORXZbw6VBw7']// this is my FCM token.
if(
const payload = {
notification: {
title: "Message",
body: "hi hello",
sound: "default"
}
};
return admin.messaging().sendToDevice(token, payload).then((response)=> {
console.info("Successfully sent notification")
}).catch(function(error) {
console.warn("Error sending notification " , error)
});
});
FCMtokenに基づいて通知を送信する方法です。
誰でも手伝ってください。 – vijju