aws-sdk-ruby icon indicating copy to clipboard operation
aws-sdk-ruby copied to clipboard

SNS JSON not being sent to the device.

Open goleador opened this issue 13 years ago • 6 comments

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.

goleador avatar Sep 12 '13 06:09 goleador

What error are you getting from the service?

Please list the output running that script through aws-rb -v yourscript.rb

lsegal avatar Sep 12 '13 06:09 lsegal

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.

lsegal avatar Sep 12 '13 07:09 lsegal

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.

lsegal avatar Sep 12 '13 07:09 lsegal

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.

awood45 avatar Sep 12 '13 17:09 awood45

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'

goleador avatar Sep 13 '13 03:09 goleador

Thank you!

goleador avatar Sep 13 '13 03:09 goleador