【问题标题】:firebase messaging conditions with multiple topics not working具有多个主题的firebase消息传递条件不起作用
【发布时间】:2018-11-02 21:43:58
【问题描述】:

我正在使用 node firebase admin 向 Android 设备发送消息。 所有作品。除非我尝试向多个主题发送消息。 在下面的示例代码中,我只是订阅了 2 个主题,然后直接在一个条件下向多个主题发送通知。我的手机上没有任何东西。当您只发送到一个主题时,通知就会成功到达。我不明白为什么它不起作用。 firebase 管理员没有错误响应。 只是:'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);
        });

【问题讨论】:

  • 您声明了topicatopicb,但使用了topic1topic2topic。发布的代码是您实际运行的代码吗?
  • 是的。我在这里粘贴代码时犯了一个错误。问题依然存在
  • dryRun 设置为什么?也许是真的?
  • @leeJensen 不,不是。我现在知道这是 Google 消息传递后端中的一个错误。他们意识到这一点。但不知何故,他们没有解决它。
  • 我知道 Web 客户端上当前存在该错误,但它在 Android 上运行良好。谷歌支持说它在他们的名单上。 (现在已经有八个月了)

标签: android firebase firebase-cloud-messaging


【解决方案1】:

这是 FCM 的一个错误。您可以通过将消息帖子拆分为多条消息来解决此问题。

改为发送一条消息。

'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 个主题的限制仍然有效。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-04
  • 1970-01-01
相关资源
最近更新 更多