AWS SNS:如何在推送通知中发送自定义数据
AWS SNS: how to send custom data within a push notification
我们有一个案例需要发送一个带有推送通知的 json 对象。阅读文档我发现我可以执行以下操作
iOS
{
default: req.body.message,
"APNS": {
"aps": {
"alert": {
"message": req.body.message,
"data": "{JSON Object}"
},
},
}
Android:
{
"GCM": {
"data": {
"messagee": {
"message": req.body.message,
"data": "{JSON Object}"
}
}
}
}
但是,我怀疑我们是否应该使用 Message Attributes
如果不是,那么 Message Attributes
的用途是什么!
根据您的描述,您似乎不需要使用消息属性。引用 the AWS docs:
You can also use message attributes to help structure the push notification message for mobile endpoints. In this scenario the message attributes are only used to help structure the push notification message and are not delivered to the endpoint, as they are when sending messages with message attributes to Amazon SQS endpoints.
有一些将消息属性附加到推送通知的用例。一个这样的用例是出站消息的 TTL。再次引用 the docs:
The TTL message attribute is used to specify expiration metadata about a message. This allows you to specify the amount of time that the push notification service, such as Apple Push Notification Service (APNS) or GCM, has to deliver the message to the endpoint. If for some reason (such as the mobile device has been turned off) the message is not deliverable within the specified TTL, then the message will be dropped and no further attempts to deliver it will be made. To specify TTL within message attributes, you can use the AWS Management Console, AWS software development kits (SDKs), or query API.
我们有一个案例需要发送一个带有推送通知的 json 对象。阅读文档我发现我可以执行以下操作
iOS
{
default: req.body.message,
"APNS": {
"aps": {
"alert": {
"message": req.body.message,
"data": "{JSON Object}"
},
},
}
Android:
{
"GCM": {
"data": {
"messagee": {
"message": req.body.message,
"data": "{JSON Object}"
}
}
}
}
但是,我怀疑我们是否应该使用 Message Attributes
如果不是,那么 Message Attributes
的用途是什么!
根据您的描述,您似乎不需要使用消息属性。引用 the AWS docs:
You can also use message attributes to help structure the push notification message for mobile endpoints. In this scenario the message attributes are only used to help structure the push notification message and are not delivered to the endpoint, as they are when sending messages with message attributes to Amazon SQS endpoints.
有一些将消息属性附加到推送通知的用例。一个这样的用例是出站消息的 TTL。再次引用 the docs:
The TTL message attribute is used to specify expiration metadata about a message. This allows you to specify the amount of time that the push notification service, such as Apple Push Notification Service (APNS) or GCM, has to deliver the message to the endpoint. If for some reason (such as the mobile device has been turned off) the message is not deliverable within the specified TTL, then the message will be dropped and no further attempts to deliver it will be made. To specify TTL within message attributes, you can use the AWS Management Console, AWS software development kits (SDKs), or query API.