问题描述
我想在创建 client
文档时向 2 种不同类型的用户发送通知。首先,我必须在 providers
集合中搜索想要附近客户的附近提供者,以及不关心距离的远程提供者,以便我可以向所有这些提供者发送通知。我尝试实现这 2 个查询并发送通知,但失败了。错误消息是 Registration token(s) provided to sendToDevice() must be a non-empty string or a non-empty array
。以下代码有什么问题?
exports.clientRegisterNotification = functions.firestore
.document("crews/{crew}/clients/{client}")
.onCreate(async (snapshot) => {
try {
const clientGeopoint = snapshot.data().g.geopoint;
const clientField = snapshot.data().field;
const nearCollection = geofirestore.collectionGroup("providers");
const remoteCollection = firestore.collectionGroup("providers");
const query1 = remoteCollection.where("wantNear","==",'false')
.where("field",clientField);
const query2 = nearCollection.near({center: clientGeopoint,radius: 10}).where("wantNear",'true')
.where("field",clientField);
const tokenArray = [];
const [remotePro,nearPro] = await Promise.all([query1.get(),query2.get()]);
remotePro.docs.forEach((doc) => {
const token1 = doc.data().fcmToken;
tokenArray.push(token1);
nearPro.docs.forEach((doc) => {
const token2 = doc.data().fcmToken;
tokenArray.push(token2);
});
const message = {
"notification": {
title: ...,body: ...,},};
admin.messaging().sendToDevice(tokenArray,message);
} catch (error) {
console.log(error);
}
});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)