SNS JSON not being sent to the device.
I am sorry but I am afraid this is an issue with the SDK. I can get the same JSON structure to work on the SNS console but not through the SDK.
sns_message = {
:default => self.subject,
:aps => {
:alert => self.subject,
:sound => 'default'
},
:payload => {
:notification_type => 'new_workout',
:workout_id => self.workout_id
}
}
AWS.sns.client.publish :subject => self.subject,
:message => sns_message.to_json,
:topic_arn => target_arn,
:message_structure => 'json'
On the device all I get is the the default message. The aps and payload sections are not being sent to the device when using the sdk.
What error are you getting from the service?
Please list the output running that script through aws-rb -v yourscript.rb
Also, have you looked at https://forums.aws.amazon.com/thread.jspa?threadID=134152&tstart=0 ? The thread uses the Node.js SDK, but you should be able to translate the call into the Ruby equivalent to get what you want. It seems this user was having a similar issue.
Judging by that forum thread, it seems that your payload has to include "APS" (uppercase) and/or "APNS_SANDBOX". This is also documented in the Mobile Push documentation.
Can you share with us the exact error you're getting? We're not able to replicate this on our end, we'd need the wire logs from aws-rb -v to look into this any further.
I finally got it:
apns_json = { :aps => { :alert => self.subject, :sound => 'default' },
:payload => {
:notification_type => 'new_workout',
:workout_id => self.workout_id
}
}.to_json
message = {
:default => self.subject,
:APNS => apns_json,
:APNS_SANDBOX => apns_json
}.to_json
AWS.sns.client.publish :subject => self.subject,
:message => message,
:topic_arn => target_arn,
:message_structure => 'json'
Thank you!