Azure推送通知中心 - 如何处理iOS和Android的有效负载格式? [英] Azure push notification hub - how to handle payload formats for both iOS and Android?

查看:236
本文介绍了Azure推送通知中心 - 如何处理iOS和Android的有效负载格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过Azure Notification Hub支持iOS和Android平台。

I am trying to support both iOS and Android platforms through the Azure Notification Hub.

iOS平台需要以下形式的有效载荷:

The iOS platform expects the payload in the form:


{aps :{{alert:通知中心测试通知}}

{"aps":{"alert":"Notification Hub test notification"}}

而Android平台需要以下列形式的有效负载:

while the Android platform expects the payload in the form:


{data:{message:通知中心测试通知}}

{"data":{"message":"Notification Hub test notification"}}

我知道可以修改有效载荷以包含更多信息,但这个例子足以解决问题。

I am aware that the payload can be modified to include more information but the example is sufficient for the question.

给定我根据标签向目的地发送通知,并且我没有记录每个推送通知注册使用哪个平台是发送通知两次的唯一选择,一次是苹果原生,第二次是gcm本地?

Given that I send a notification to a destination based on a Tag and I do not keep a record of which platform each push notification registration uses is the only alternative to send the notification twice, once for apple native and the second for gcm native?


hubClient.SendAppleNativeNotificationAsync(payload,tag);
hubClient.SendGcmNativeNotificationAsync(payload,tag);

hubClient.SendAppleNativeNotificationAsync(payload, tag); hubClient.SendGcmNativeNotificationAsync(payload, tag);

或者,有没有办法向Azure Notification Hub发送通知有多个有效负载,然后通知集线器将使用适用于目标设备的有效负载?

Or, is there a way to send a notification to Azure Notification Hub with multiple payloads and then the notification hub will use the payload appropriate for the destination device?

推荐答案

您提供的解决方案已足够是最好的方式。

The solution you present is sufficient and is the best way.

如果你真的想避免额外的通话(同样不需要额外拨打通知中心)。

If you really want to avoid the extra call (again there is no need to make the extra calls to notification hub).


  1. 注册设备时还注册类型标签

  2. 查询type标记的通知中心和要发送到的其他标记

  1. when you register the device also register a "type" tag
  2. query the notification hub for the "type" tag and the other tag you want to send to

for(hubClient.getRegistrationsByTag(iosTag)中的注册注册){
hubClient .SendAppleNativeNotificationAsync(payload,tag);
}

for (Registration reg in hubClient.getRegistrationsByTag(iosTag)) { hubClient.SendAppleNativeNotificationAsync(payload, tag); }

for(hubClient.getRegistrationsByTag(androidTag)中的注册注册){
hubClient.SendGcmNativeNotificationAsync(payload,tag);
}

for (Registration reg in hubClient.getRegistrationsByTag(androidTag)) { hubClient.SendGcmNativeNotificationAsync(payload, tag); }

这篇关于Azure推送通知中心 - 如何处理iOS和Android的有效负载格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆