我在用户注册时发送推送通知,它只向注册用户发送通知,我可以将其更改为使用该应用程序的每个人吗?



下面的代码是我的火力基础函数索引.js文件

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref("Notifications/{userId}")
.onWrite(event => {
var request = event.data.val();
var payload = {
data: {
title: "Welcome to ChitChat Group",
message: "You may have new messages"
}
};
admin.messaging().sendToDevice(request.token, payload)
.then(function (response) {
console.log("Successfully sent message: ", response);
})
.catch(function (error) {
console.log("Error sending message: ", error);
})    
});

下面的代码包含用户注册时我装箱令牌的位置

String uid = (String) firebaseAuth.getCurrentUser().getUid();
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Notifications/"+uid);
reference.child("token").setValue(FirebaseInstanceId.getInstance().getToken());

您可以让所有用户订阅一个大主题,例如registrationonnewMembers然后向该主题发送通知:

var message = { 
to: '/topics/newMembers',  
notification: {
title: 'title', 
body: 'body' 
},
}; 

相关内容

  • 没有找到相关文章

最新更新