Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNS JSON not being sent completely to the iOS device #1299

Closed
Migoo opened this issue Sep 21, 2016 · 3 comments
Closed

SNS JSON not being sent completely to the iOS device #1299

Migoo opened this issue Sep 21, 2016 · 3 comments
Labels
feature-request A feature should be added or improved. service-api General API label for AWS Services.

Comments

@Migoo
Copy link

Migoo commented Sep 21, 2016

Hello,

I'm trying to send a custom message through SNS on both Android and iOS devices.

Here is the json i'm sending to the publish method of Aws::SNS::Client.new:

{
      default: push_notification_text(locale),
      GCM: {
        data: {
          offer_preview: {
            title: website.name,
            content: push_notification_text(locale),
            offer_id: id
          }
        }
      }.to_json,
      APNS: {
        aps: {
          alert: {
            title: website.name,
            body: push_notification_text(locale)
          },
          payload: {
            website_identifier: website.identifier,
            type: 'offer_preview',
            id: id
          }
        }.to_json
      }
    }.to_json

For the GCM it's working fine. But for iOS the device receive only the aps key of the json. the payload are not send to the device.

I try many things to fix it, but I didn't find any working solution.
Am I doing something wrong ?
Thanks for helping

Jonathan

@awood45
Copy link
Member

awood45 commented Sep 27, 2016

I'm noticing the :to_json calls embedded at multiple points. Is this intentional? Perhaps you could pull out the generated JSON string (anonymizing as needed) to verify. This looks like either a usage issue or service issue on the surface.

@awood45 awood45 added information requested service-api General API label for AWS Services. labels Sep 27, 2016
@Migoo
Copy link
Author

Migoo commented Sep 28, 2016

Hello,

Thanks for your answer.
in Fact we found the solution, here is the modified json:

{
      default: push_notification_text(locale),
      GCM: {
        data: {
          offer_preview: {
            title: website.name,
            content: push_notification_text(locale),
            offer_id: id
          }
        }
      }.to_json,
      APNS: {
        aps: {
          alert: {
            title: website.name,
            body: push_notification_text(locale)
          },
          payload: {
            website_identifier: website.identifier,
            type: 'offer_preview',
            id: id
          }
        }
      }.to_json
    }.to_json

note that we just move a to_json from aps to APNS object.

And yes it's intentional to have the multiple json. It's inspired by this Php issue on stackoverflow:
http://stackoverflow.com/questions/18845984/how-to-send-extra-parameters-in-payload-via-amazon-sns-push-notification

It was really tricky to implement and find a working solution.
I'm wondering if it's possible to have this json serialization directly in the gem. Like this we just have to pass our hash.

here is our ouptut serialized json:
{:default=>"Qwine.ch: Port Charlotte Scottish Barley pour 89.– au lieu de 119.90", :GCM=>"{\"data\":{\"offer_preview\":{\"title\":\"Qwine.ch\",\"content\":\"Qwine.ch: Port Charlotte Scottish Barley pour 89.– au lieu de 119.90\",\"offer_id\":1000012}}}", :APNS=>"{\"aps\":{\"alert\":{\"title\":\"Qwine.ch\",\"body\":\"Qwine.ch: Port Charlotte Scottish Barley pour 89.– au lieu de 119.90\"},\"sound\":\"default\",\"payload\":{\"website_identifier\":\"qwineqoqach\",\"type\":\"offer_preview\",\"id\":1000012}}}", :APNS_SANDBOX=>"{\"aps\":{\"alert\":{\"title\":\"Qwine.ch\",\"body\":\"Qwine.ch: Port Charlotte Scottish Barley pour 89.– au lieu de 119.90\"},\"sound\":\"default\",\"payload\":{\"website_identifier\":\"qwineqoqach\",\"type\":\"offer_preview\",\"id\":1000012}}}"}

Thanks a lot for helping and improving the gem if possible

@awood45 awood45 added feature-request A feature should be added or improved. and removed information requested labels Oct 14, 2016
awood45 added a commit that referenced this issue Nov 29, 2016
Related to GitHub issues:

* #1299
* #1323
* #1335
* #1336
@awood45
Copy link
Member

awood45 commented Nov 29, 2016

Added to feature request backlog.

@awood45 awood45 closed this as completed Nov 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. service-api General API label for AWS Services.
Projects
None yet
Development

No branches or pull requests

2 participants