具有多个主题的firebase消息传递条件不起作用 [英] firebase messaging conditions with multiple topics not working

查看:93
本文介绍了具有多个主题的firebase消息传递条件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用节点firebase admin将消息发送到Android设备. 所有作品.除了当我尝试将消息发送到多个主题时. 在下面的示例代码中,我只需订阅2个主题,然后直接在某种情况下向多个主题发送通知.我的手机上什么都没收到.当您仅发送一个主题时,通知会成功到达.我不明白为什么它不起作用. firebase管理员没有错误响应. 只是:"projects/admob-app-id-xxxx/messages/xxxx"

I am using the node firebase admin to send messages to Android devices. All works. Except when I try to send messages to multiple topics. In the example code below I simply subscribe to 2 topics and directly afterwards i send a notifications to multiple topics in a condition. Nothing arrives on my Phone. When you just send to one topic, the notification arrives successfully. I don't get why it is not working. There is no error response from the firebase admin. just: 'projects/admob-app-id-xxxx/messages/xxxx'

var admin = require("firebase-admin");
var serviceAccount = require("./serviceAccountKey.json");
admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
databaseURL: "https://admob-app-id-xxxxx.firebaseio.com"
});

var registrationTokens = ["xxxxx"];
var topica = "AAA";
var topicb = "BBB";
var data = {};

var message = { 
            condition : "'"+topica+"' in topics || '"+topicb+"' in topics",
            data: {'message':JSON.stringify(data)},
            android: {
                ttl: 36000 * 1000,
                priority: 'normal',
                collapseKey: "test"
            }
        };



        admin.messaging().subscribeToTopic(registrationTokens, topica)
            .then(function(response) {

                admin.messaging().subscribeToTopic(registrationTokens, topicb)
                    .then(function(response) {

                        admin.messaging().send(message, dryRun)
                            .then((response) => {
                            console.log('success', response);
                    }).catch((error) => {
                            console.log('error', error);
                    });

                    })
                .catch(function(error) {
                    console.log('Error subscribing to topic:', error);
                });
            })
            .catch(function(error) {
                console.log('Error subscribing to topic:', error);
        });

推荐答案

这是FCM的错误.您可以通过将消息发布分解为多条消息来解决此问题.

This is a bug with FCM. You can work around it by breaking up your message post into multiple messages.

发送一条消息.

't1' in topics || 't2' in topics || 't3' in topics

发送相等的三个消息.

't1' in topics && !('t2' in topics) && !('t3' in topics)
't2' in topics && !('t3' in topics)
't3' in topics

请注意,第5个主题的限制仍然有效.

Note that the 5 topic limit is still in force.

这篇关于具有多个主题的firebase消息传递条件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆