【发布时间】:2021-03-02 13:57:44
【问题描述】:
我刚刚开始学习 react-native 并考虑将 firebase 集成到其中。现在考虑我的问题场景:
有两个用户 A 和 B 在他们的设备上运行了 react 应用程序(他们都不是管理员)。现在我研究了当我们将我们的 React Native 应用程序连接到 Firebase 时,在设备上运行的应用程序的每个实例都会获得一个唯一的令牌,并且该令牌存储在 Firebase 本身中。
现在假设用户 A 想向用户 B 发送“通知或消息”。现在看一下我在 firebase 官网上看到的以下代码:
// This registration token comes from the client FCM SDKs.
var registrationToken = 'YOUR_REGISTRATION_TOKEN';
var message = {
data: {
score: '850',
time: '2:45'
},
token: registrationToken
};
// Send a message to the device corresponding to the provided
// registration token.
admin.messaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
})
.catch((error) => {
console.log('Error sending message:', error);
});
这个方法看起来很简单,但是真的有什么方法可以让用户A像这样知道用户B的唯一令牌吗:
const token= firebase.getToken('B');
然后在上面的代码中使用这个令牌向用户B发送通知。使用firebase可以做到吗?
谢谢。
【问题讨论】:
标签: android firebase react-native push-notification firebase-cloud-messaging