简体   繁体   English

Nodejs Firebase 云消息传递延迟交付 android

[英]Nodejs Firebase cloud messaging delayed delivery on android

I'm trying to push some high-priority data messages from a nodejs backend to the android client.我正在尝试将一些高优先级的数据消息从 nodejs 后端推送到 android 客户端。 Here is my code,这是我的代码,

var payload = {
        data
      };

var options = {
        priority: "high",
        timeToLive: 0,
        ttl: 0,
        android: {
          priority: "high",
          timeToLive: 0,
          ttl: 0,
        },
      };

   admin.messaging()
        .sendToDevice(deviceFcmId, payload, options)
        .then(function (response) {})
        .catch(function (response) {
          console.error("error sendNotification", response);
        });

As you can see, I'm using priority "high" and timeToLive: 0 .如您所见,我正在使用priority "high"timeToLive: 0 But this does not wake up the device if it is in Doze mode, or sometimes even if the device is in an unlocked state, the message is delayed up to a few minutes.但这不会唤醒处于Doze模式的设备,或者有时即使设备处于解锁的 state 中,消息也会延迟几分钟。 This is a voice-calling app, so the delivery delay should be minimal.这是一个语音通话应用程序,因此交付延迟应该是最小的。 I've searched similar posts on StackOverflow but nothing works for me.我在 StackOverflow 上搜索过类似的帖子,但对我没有任何帮助。 What am I missing here?我在这里想念什么? Thanks in advance.提前致谢。

From the official docs来自官方文档

High priority messages on Android are meant for time sensitive, user visible content, and should result in user-facing notifications. Android 上的高优先级消息适用于时间敏感、用户可见的内容,并应导致面向用户的通知。 If FCM detects a pattern in which messages do not result in user-facing notifications, your messages may be deprioritized to normal priority.如果 FCM 检测到消息不会导致面向用户的通知的模式,则您的消息的优先级可能会降低为正常优先级。 FCM uses 7 days of message behavior when determining whether to deprioritize messages; FCM 使用 7 天的消息行为来确定是否取消消息的优先级; it makes this determination independently for every instance of your application.它为您的应用程序的每个实例独立做出此决定。 If, in response to high priority messages, notifications are displayed in a way that is visible to the user, then your future high-priority messages will not be deprioritized.如果作为对高优先级消息的响应,通知以用户可见的方式显示,那么您未来的高优先级消息将不会被取消优先级。

This means your android app should pretty much just show a notification (make sure the app has notifications enabled).这意味着您的 android 应用程序应该几乎只显示通知(确保应用程序启用了通知)。 If you abuse this and instead try to directly do other things when receiving the push (such as open connections to the backend or do any other computationally-expensive task) then your messages might be downgraded to normal priority.如果您滥用这一点,而是在接收推送时尝试直接做其他事情(例如打开与后端的连接或执行任何其他计算成本高的任务),那么您的消息可能会降级为正常优先级。

On a single device, you can verify if a message has been deprioritized by checking if getPriority() returns a lower value than getOriginalPriority() .在单个设备上,您可以通过检查getPriority()返回的值是否低于getOriginalPriority()来验证消息是否已被取消优先级。 And for all messages, you can query the Data API .对于所有消息,您可以查询数据 API

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM