当前位置: 动力学知识库 > 问答 > 编程问答 >

amazon web services - AWS SNS: how to send custom data within a push notification

问题描述:

We have a case where we need to send a json object with a push notification. Reading the documentation I found out I can do the following

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}"

}

}

}

}

But, I got sceptical if we should use Message Attributes if not then what is the us of the Message Attributes !

网友答案:

Based on your description it seems like you do not need to use message attributes. Quoting 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.

There are some use cases for attaching message attributes to push notifications. One such use case is for TTLs on outbound messages. Again quoting 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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: