2 回答

TA貢獻1804條經驗 獲得超2個贊
有兩種方法可以做到這一點。第一種方式發送 1000 然后 1000 ..等等。第二種方式是發送到特定主題,所有訂閱該主題的客戶都會收到您的通知。
此代碼發送 1000 然后 1000 ..etc。但我不喜歡它。你應該使用topic-messaging
它來代替它。
for (let i = 0; i < listOf5000Tokens.length; i += 1000) {
const listOf1000Tokens = listOf5000Tokens.slice(i, i + 1000);
// using await to wait for sending to 1000 token
await doSomeThing(listOf1000Tokens);
}

TA貢獻1851條經驗 獲得超5個贊
您需要分批發送消息。
例如:
// Create a list containing up to 500 messages.
const messages = [];
messages.push({
notification: {title: 'Price drop', body: '5% off all electronics'},
token: registrationToken,
});
messages.push({
notification: {title: 'Price drop', body: '2% off all books'},
topic: 'readers-club',
});
admin.messaging()
.sendAll(messages)
.then((response) => console.log(response.successCount + ' messages were sent successfully'));
添加回答
舉報