通过 Azure 通知中心上的 GCM 发送高优先级消息

Sending high priority message via GCM on Azure Notification Hub

我正在使用 AzureNotification Hub 将 GCM 通知发送到我的 Android 应用程序。我的问题是默认情况下,SDK 使用什么优先级发送通知,是否可以对其进行配置。根据我在 Google 的网站 https://developers.google.com/cloud-messaging/concept-options?hl=en 上看到的内容,我可以简单地将优先级添加为有效负载的一部分。但是我不确定底层 SDK 如何处理这个问题以及它是否默认添加优先级。这就是我所做的。通知是用下面的代码发送的,但我想知道优先级值是否有任何影响。

var payload = new
{
priority="high",
data = new
{
message = new
{
model.Title,
model.Time,
model.Message,
model.NotificationId,
model.NotificationType,
model.SenderFacebookId,
model.TargetId,
model.TargetUserFacebookId
}
}
};

var json = JsonConvert.SerializeObject(payload);
await hub.SendGcmNativeNotificationAsync(json, Tag.UserDevice.Id);

确实优先级次于Azure平台https://azure.microsoft.com/en-in/documentation/articles/notification-hubs-nodejs-how-to-use-notification-hubs/ The priority values are actually part of the http header being sent by azure to the Google servers, essentially the notification is still coming via the google server and Azure just sends the bundle to Google , the valid values can be checked here https://msdn.microsoft.com/library/hh221551.aspx

您添加优先级(作为数据的同级)的方式应该可行。默认的 GCM 优先级是正常的,所以如果你没有分配优先级,它就会被视为正常。这意味着不同平台上的情况略有不同,但一般来说,高优先级消息将尽快传递,而普通优先级消息将在下一个最佳时间传递,具体取决于各种设备条件。

开启 Android GCM 优先级可帮助设备在处于 Doze 模式时决定何时传递消息。需要用户操作的消息(如聊天消息)应获得高优先级,Android 将尝试尽快传送它们。大多数消息(如同步新服务器数据)应分配正常优先级,Android 将尝试在设备的下一个最佳时间传送它们。