我有一个包含两个应用程序(两个目标)的xCode项目,我正尝试从特定目标发送FCM,但它总是从第一个目标发送!
在index.js文件中
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.sendNotificationForCompany = functions.firestore.document('test/{referenceID}').onCreate(async (snap, context) => {
var theTitle = "Not"
let payload = {
notification: {
title: theTitle,
sound: 'default',
}
};
const allTokens = await admin.firestore().collection('users').get();
const tokens4 = [];
allTokens.forEach((tokenDoc) => {
if (tokenDoc.data().instanceIdToken){
tokens4.push(tokenDoc.data().instanceIdToken)
}
});
admin.messaging().sendToDevice(tokens4, payload);
});
You can sent notification based on topic. For example
project-one-topic-unique-user-id
andproject-two-topic-unique-user-id
. So now send notification based on topic