I absolutely broke my head. I have code which send SNS (AWS) for iOS with line:
PublishRequest publishRequest = new PublishRequest("arn:aws:sns:us-east-1:my:topic", messageBody);
and it works fine when I pass there Json like this:
{"message": "ldjldkjlk"}
But of course I need sound to my notification and nothing is works for me. I tried with Json which works when I pass it to SNS GUI, something like that:
{"message": {
"default": "HERE IS AN ALERT, BADGE, and SOUND",
"APNS_SANDBOX": "{\"aps\": {\"alert\":\"HERE IS AN ALERT, BADGE, and SOUND!\",\"badge\": 1,\"sound\":\"bingbong.aiff\"}}"
}}
But I get error:
{"timestamp":1435334944602,"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"Could not read JSON: Can not deserialize instance of java.lang.String out of START_OBJECT token\n at [Source: java.io.PushbackInputStream@2db14d22; line: 1, column: 15]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token\n at [Source: java.io.PushbackInputStream@2db14d22; line: 1, column: 15]","path":"/sns/send"}
What did they do with PublishRequest? What I should pass there? It will be amazing if somebody helps me!
OMG I found an answer for myself it should be like this:
String message = "{\"apn\": { \n" +
" \"default\": \"HERE IS AN ALERT, BADGE, and SOUND\",\n" +
" \"APNS_SANDBOX\": \"{\\\"aps\\\": {\\\"alert\\\":\\\"HERE IS AN ALERT, BADGE, and SOUND!\\\",\\\"badge\\\": 1,\\\"sound\\\":\\\"bingbong.aiff\\\"}}\"\n" +
"}}";
publishRequest.setMessage(message);
publishRequest.setMessageStructure("json");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.