Fil*_*ipe 5 ruby android amazon-web-services amazon-sns ios
我正在尝试使用亚马逊的Ruby SDK发送带有针对不同平台的附加属性的推送通知,即APNS和GCM(Apple和Android设备),但我找不到使用SDK的API发送记录的消息结构的方法.
要为GCM和APNS发送具有不同有效负载的消息,我发现的文档建议使用以下结构:
{
"APNS": {
"aps": {
"alert": "someone set us up the bomb"
}
},
"GCM": {
"data": {
"message": "we get signal"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我希望SNS能够将特定于平台的有效负载正确地发送到正确的平台端点,但是相反,例如,Android设备的消息也包括APNS有效负载 - 它包括完整的消息体.
这是我发送消息的方式:
sns = AWS::SNS::Client.new
sns.publish(
target_arn: endpoint_arn,
message: {
GCM: ...,
APNS: ...
}.to_json
)
Run Code Online (Sandbox Code Playgroud)
可用的文档,特别是对于ruby sdk,似乎并没有那么详细.我是否认为有效载荷应根据端点平台正确分配?有没有更好的方法来实现我想要做的事情?
小智 3
也许您已经明白了这一点,但以下是它在 PHP 上的工作原理。Ruby 中的消息结构可能是相同的:
publish(array(
'TopicArn' => 'YOUR_TOPIC_ARN',
'Message' => '{
"default": "YOUR_MESSAGE",
"email": "YOUR_MESSAGE",
"sqs": "YOUR_MESSAGE",
"http": "YOUR_MESSAGE",
"https": "YOUR_MESSAGE",
"sms": "YOUR_MESSAGE",
"APNS": "{\"aps\":{\"alert\": \"YOUR_MESSAGE\",\"sound\":\"default\", \"badge\":\"1\"} }",
"GCM": "{ \"data\": { \"message\": \"YOUR_MESSAGE\" } }",
"ADM": "{ \"data\": { \"message\": \"YOUR_MESSAGE\" } }"
}',
'MessageStructure' => 'json'
));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1605 次 |
| 最近记录: |