-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
How to send an APN alert message with a sound using SNS mobile push notifications? #336
Comments
Can you provide more details on what doesn't work? If you are getting an error, please provide the full stack trace. |
I get the message on the phone but it's just the JSON. I expected it to play a sound and to display just the message not the json. { Basically it displays the whole text above when I expected |
I am trying this now still does not work:
|
It works if sending from AWS Console |
I'm reading through the Java sample application provided in the mobile push getting started guide, and it seems as though they set the MessageStructure parameter to 'json'. This might be required. See line 229 of the message = { :default => "Default message", :aps => { :alert => params[:message]}}.to_json
AWS.sns.client.publish :message => message, :target_arn => target, :message_structure => 'json' Note that you also need a "default" key at the root of your JSON object if you use the 'json' message structure. See the Ruby docs for #publish and the API docs for more info on this parameter. I can't test this myself, so let me know if this works for you. |
NICE! It worked. Thank you again @lsegal . |
Glad you got it working! |
@isegal thanks you solve my problem! you rocks guy! |
Hi i'm try to send notifications whit sound and badge but only recibe default text
message = { :default => "Credito aprobado", :APNS_SANDBOX => {:aps => { :alert =>'Test',:badge =>'1',:sound =>'default'}}}.to_json
AWS.sns.client.publish :message => message, :target_arn => topic_arn, :message_structure => 'json'
Im not understand what is the problem?
any ideas?
Regards
|
I use the following in PHP $title = 'My Test Message'; $response = $sns->publish(array( |
@ingscjoshua did you resolve this issue? I'm having the same problem. |
For anyone else who arrives here, the issue is very similar to the issue discussed in the aws-sdk-js library above. You have to encode your json twice (sigh). Working code in ruby for aws-sdk: client = AWS::SNS::Client.new
apns_payload = { "aps" => { "alert" => "hey it worked!", "badge" => 14 } }.to_json
message = { "default" => "this is the default", "APNS" => apns_payload }.to_json
client.publish( message: message, target_arn: your_endpoint_arn, message_structure: 'json' ) |
This is also incorrect (or at least has changed as of today) The following works for me and successfully plays a sound:
|
Suddenly started having SNS turn endpoints 'Enabled' to 'false' all by itself. Also I tried bulding the json by hand and still not working. Here is what I tried. Any help is appreciated. Thanks message = {"default" => 'Test text', "APNS_SANDBOX" => {"aps" => {"alert" => "Test text", 'badge' => 1, 'sound' => 'default'}}}.to_json gives me a message_id and a request_metadata with request_id as subkey. Is there a place to look at the logs for these requests. At least on sandbox? |
@jmstone617, your solution works for me. Double to_json, and sound: 'default' seems to do it. |
I'm use the AWS Java SDK, and this thread really helped me. Apparently all SNS SDKs require the platform-specific payload to be a string and not a nested object. Encoding my JSON twice fixed the issue. |
This is not working:
AWS.sns.client.publish :message => { :aps => { :alert => params[:message]}}.to_json, :target_arn => target
I can send a message just fine. But if I try to structure the JSON it doesn't work.
The text was updated successfully, but these errors were encountered: