AWS SNS - Push for GCM showing as sent from Cloudw

2019-08-24 05:00发布

问题:

I am migrating from custom Push Notification to AWS SNS. I did the following.

  • configured AWS SNS Topic
  • Created Platform Application
  • created Endpoints
  • Suscribed endpoints to Platform Application

I am trying the last step for Pushing the Notification using 'publish' API for Ruby. I receive the message_id as response. It also logs as success / delivered in CloudWatch. But the Push is not received in the device.

The device is valid The device has a valid push token the device has the application installed.

The message format I tried areas follows

{"GCM"=>{"data"=>"{\"message\":\"message\",\"url\":\"url\"}"}, :default=>"default"}

SNS publish API syntax

client.publish({target_arn: endpoint_arn, message: message.to_json, subject: "SNS test", message_structure: :json})

FYI, Before marking this as duplicate of any other question, please note that i have referred all previous answers and nothing helped me. hence I am raising a new one.

回答1:

The GCM payload format is updated. This works for me.

{
"GCM": "{ \"notification\": { \"body\": \"hello....\", \"title\": \"title123\" } }"
}


回答2:

There is a problem with my message formation. I figured it out by debugging with android . The Push reached the device but it was not in the expected format. So the push was not shown in the device. I was sending

{"GCM"=>{"data"=>"{\"message\":\"message\",\"url\":\"url\"}"}, :default=>"default"}

But the Android system was expecting 'badge' and some other keys in my message. I tried with

 {:default=>"default", :GCM=>"{\"data\":{\"message\":\"test\",\"url\":\"https://s3.amazonaws.com/mcds_fulltext/aapg/gsaapgbull/issues/74/android_hdpi/cover_74.gif\",\"registration_ids\":\"arn:aws:sns:us-****-1:*********7:endpoint/GCM/gs*****_gcm/*********************\",\"badge\":\"10\",\"vol\":\"128\",\"issue\":\"10\",\"journal_name\":\"gsaapg\",\"abbr\":\"aapg\"},\"collapse_key\":\"New Article badge\"}"}

Now it works as expected.

This particular JSON might not be appropriate for everyone. But the cause of this issue is the message JSON is not in the expected format for the mobile app. This might be helpful for someone who face the similar issue.