设置Fcm通知优先级

设置Fcm通知优先级

本文介绍了设置Fcm通知优先级-Azure通知中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在C#SDK的Fcm通知有效载荷上设置高优先级",以便从后端将其发送到移动应用程序.站在Fcm文档中,Json Paylod应该看起来像这样:

I am trying to set High Priority on an Fcm Notification Payload in C# SDK in order to send it the a mobile application from the Back-End.Standing to the Fcm Documentation the Json Paylod should look like this:

{
  "message":{
    "topic":"subscriber-updates",
    "notification":{
      "body" : "This week's edition is now available.",
      "title" : "NewsMagazine.com",
    },
    "data" : {
      "volume" : "3.21.15",
      "contents" : "http://www.news-magazine.com/world-week/21659772"
    },
    "android":{
      "priority":"normal"
    },
    "apns":{
      "headers":{
        "apns-priority":"5"
      }
    },
    "webpush": {
      "headers": {
        "Urgency": "high"
      }
    }
  }
}

在此处找到

在我的代码中,我尝试了使用Azure SDK的不同方法. 1

In my code i tried diffent ways to do that with the Azure SDK.1

var result = await voipClient.SendFcmNativeNotificationAsync(payload, tag);

将此json放入有效载荷

Putting as payload this json

{
   "data":{
      "key":"value"
},
   "android":{
      "priority":"high"

}

2

var notification = new FcmNotification(payload);
notification.Headers.Add("android", "{\"priority\": \"high\"}");

将广告有效负载放入我之前发布的有效负载

Putting ad payload the one i posted before

在两种情况下,我都会收到具有正常优先级的通知.

In both cases i receive the notification with normal priority.

你知道我在哪里犯错吗?

Do you know where i'm making mistakes?

推荐答案

如果您查看Azure Notification Hub文档,可能会感到困惑,因为它链接到FCM文档:FCM允许使用不同的方式来构建有效负载,Notification Hub更严格.

If you look at Azure Notification Hub documentation you could get confused because it links to FCM documentation: FCM allows different ways to build the payload, Notification Hub is stricter.

您应该发送以下有效载荷:

You should send the following payload:

{
   "data":{
      "key1":"value1",
      "key2":"value2",

   },
  "priority":"high"
}

您发送到Notification Hub的负载实际上是Firebase负载内部的"android"字段.

The payload you send to Notification Hub is in fact the "android" field inside the Firebase payload.

注意:如果将通知字段内的标题设置如下,则Notification Hub会自动将优先级设置为 high :

Note:The priority is set automatically to high by Notification Hub if you set the title inside the notification field as follow:

{
  "notification": {
    "title":"any title"
  }
}

这篇关于设置Fcm通知优先级-Azure通知中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 13:09