Typescript 如何收集特定令牌以向特定设备发送推送通知
这是我过滤用户联系人的地方,我这样做只是为了获取用户的联系人,如果他们创建了帐户,那么他们将显示在您的屏幕上。(还有更多内容,但这只是为了更直观)Typescript 如何收集特定令牌以向特定设备发送推送通知,typescript,firebase,flutter,push-notification,firebase-cloud-messaging,Typescript,Firebase,Flutter,Push Notification,Firebase Cloud Messaging,这是我过滤用户联系人的地方,我这样做只是为了获取用户的联系人,如果他们创建了帐户,那么他们将显示在您的屏幕上。(还有更多内容,但这只是为了更直观) 我发现了一个软件包,它实际上允许您从前端到后端进行通信。使用cloud_functions Flatter软件包我发现了一个软件包,它实际上允许您从前端到后端进行通信。使用cloud_functions Flatter软件包时,我在理解问题所在方面遇到问题。我添加了一个问题部分@Dougstevenson我不知道“过滤后端的联系人”是什么意思。你还没
我发现了一个软件包,它实际上允许您从前端到后端进行通信。使用cloud_functions Flatter软件包我发现了一个软件包,它实际上允许您从前端到后端进行通信。使用cloud_functions Flatter软件包时,我在理解问题所在方面遇到问题。我添加了一个
问题部分@Dougstevenson我不知道“过滤后端的联系人”是什么意思。你还没有说你的代币收集会有什么帮助。我在我的应用程序中使用flutter包,我过滤了用户的联系人,这意味着只有他们的联系人才会显示在主屏幕上(如果他们创建了帐户)。我问我是否需要在后端再做一次,然后过滤代币,如果不需要,那么我可以通过从前端到后端的通信来实现吗?我在理解问题所在方面遇到了问题。我添加了一个问题部分@dougstevenson我不知道你的意思“过滤后端的联系人”。你没有说任何关于代币收集的有用信息。我在应用程序中使用flutter包,我过滤了用户的联系人,这意味着只有他们的联系人才会显示在主屏幕上(如果他们创建了帐户).我问我是否必须在后端再做一次,然后过滤代币,如果没有,那么我可以通过从前端到后端的通信来完成吗?
List<PhonesContacts> phoneContacts = snapshot.data;
List myContacts = [];
for (var j = 0; j < phoneContacts.length; j++) {
myContacts.contains(phoneContacts[j])
? null
: myContacts.add(phoneContacts[j]);
}
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
admin.initializeApp();
const db = admin.firestore();
const fcm = admin.messaging();
export const sendToDevice = functions.firestore
.document('stat/{statId}')
.onUpdate(async change => {
const data = change.after.data();
const currentUser = await db
.collection("profile")
.doc(data.uid)
.get();
const name = currentUser.get("name");
const querySnapshot = await db
.collection('tokens')
.get();
/* Somewhere here I would access their contacts and filter it, then get their tokens and put it in the array OR if I can, I would just send the already filtered contacts I did in the front end, then just put the tokens in the array */
const tokens = querySnapshot.docs.map(snap => snap.data().token);
const payload: admin.messaging.MessagingPayload = {
notification: {
title: name,
body: data.stat,
click_action: 'FLUTTER_NOTIFICATION_CLICK'
},
data: {
click_action: 'FLUTTER_NOTIFICATION_CLICK',
title: name,
body: data.stat
}
};
return fcm.sendToDevice(tokens, payload);
});