Orest
Orest

Reputation: 6748

Amazon SNS invalid message structure for APNS

I've implemented Amazon SNS for push notifications.

I'm sending json in the following structure:

{
  "aps":{
    "alert":{
      "loc-args":["ARGS"],
      "loc-key":"KEY",
    }
    "sound":"default"
  }
}

But on iOS client I'm receiving it as escaped string and everything from my message is inside "alert" key

[AnyHashable("aps"): {
   alert = "{\"aps\":{\"alert\":{\"loc-args\":[\"ARGS\"],\"loc-key\":\"KEY\"},\"sound\":\"default\"}";
}]

I've also tried different formats from here http://docs.aws.amazon.com/sns/latest/dg/mobile-push-send-custommessage.html but every-time I'm receiving the same escaped string.

Does anyone had the same problem?

Upvotes: 1

Views: 730

Answers (1)

Orest
Orest

Reputation: 6748

So the problem was in publishRequest.setMessageStructure("json"); flag. I've missed it.

Also notification should be sent in the following format:

{"APNS_SANDBOX":"{\"aps\":{\"alert\":{\"loc-args\":[\"ARGS\"],\"loc-key\":\"KEY\"},\"sound\":\"default\"}}

Upvotes: 1

Related Questions