我发送推送通知时,用户注册,它只发送通知给注册用户,我可以改变,每个人都使用该应用程序?

下面的代码是我的firebase函数index.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); }) }); 

下面的代码包含我在用户注册时创build的令牌

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

您可以让所有的用户订阅一个像newMembers registration大话题,然后发送通知给主题:

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