firebase - Firebase 推送通知传送缓慢

我使用 Firebase Cloud Functions 来监听 Firestore 的变化并相应地发送推送通知。但是,这些通知非常慢。他们几乎有一分钟的延迟到达最终用户。对于我正在创建的聊天应用程序不太好,应该是即时的。

这是来自云函数的代码,它负责监听和发送通知:

              admin.firestore()
              .collection('users')
              .where('id', '==', idFrom)
              .get()
              .then(querySnapshot2 => {
                querySnapshot2.forEach(userFrom => {
                  console.log(`Found user from: ${userFrom.data().nickname}`)
                  const payload = {
                    notification: {
                      title: `You have a message from "${userFrom.data().nickname}"`,
                      body: contentMessage,
                      priority: 'high',
                      badge: '1',
                      sound: 'mytone'
                    }
                  }
                  // push to the target device
                  admin
                    .messaging()
                    .sendToDevice(userTo.data().pushToken, payload)
                    .then(response => {
                      console.log('Successfully sent message:', response)
                    })
                    .catch(error => {
                      console.log('Error sending message:', error)
                    })
                })
              })

有什么办法可以改善吗?

最佳答案

延迟的原因是 FCM 发送推送通知的间隔,如本 post 中所述.此行为无法在客户端解决。

https://stackoverflow.com/questions/63854943/

相关文章:

linux - 用 n 步旋转文本文件中的行

python - 使用 Python 的双向方差分析

python - open() 中的整数文件描述符 "0"

python - 无法通过 Pip 安装 TensorFlow

variables - 如何在 Pyomo 模型中设置决策变量的初始值

python-3.x - python 3.8 flask apache 2.4 wsgi 多处理运

r - 如何使用 R 中的 rcv 和 networkD3 包在 D3 Sankey 图的节点中添加

scala - 在读取 CSV 时,最后一列在 Spark、Scala 中显示为 Null

python-3.x - 安装 github 子模块时,诗歌安装失败并显示 [CalledProce

python - 在使用 pyspark 和预定义的结构模式读取嵌套的 JSON 时,如何将缺失的列