向主题发布消息

Publish message to topic

我正在尝试弄清楚如何将相同的消息发布到主题。问题是主题可以包含来自 iOS 和 Android 用户的订阅,并且 iOS 和 Android.

有不同的有效负载

如果我有主题标签,用户就会订阅。我是否必须为同一标签创建双重主题 (iOS+Android)?

A​​mazon SNS 的 Publish 功能允许将不同的有效负载传递给不同消息服务的订阅者。

来自Send Custom Platform-Specific Payloads in Messages to Mobile Devices

To send a message to an app installed on devices for multiple platforms, such as GCM and APNS, you must first subscribe the mobile endpoints to a topic in Amazon SNS and then publish the message to the topic. The following example shows a message to send to subscribed mobile endpoints on APNS, GCM, and ADM:

{ 
"default": "This is the default message which must be present when publishing a message to a topic. The default message will only be used if a message is not present for 
one of the notification platforms.",     
"APNS": "{\"aps\":{\"alert\": \"Check out these awesome deals!\",\"url\":\"www.amazon.com\"} }",
"GCM":"{\"data\":{\"message\":\"Check out these awesome deals!\",\"url\":\"www.amazon.com\"}}",
"ADM": "{ \"data\": { \"message\": \"Check out these awesome deals!\",\"url\":\"www.amazon.com\" }}" 
}