I have code like the below to send push notification. It is sent but with no sound on notification.
$sns = App::make('aws')->createClient('sns');
$sns->publish(array(
'TargetArn' => ‘arn:aws:sns:us-east-1:757730885501:endpoint/APNS/…..’,
'Message' => ‘Test message’
));
Any suggestions please?!
Try this,
For iOS device, use like this
$apns_payload = json_encode(array("aps" => array("alert" => "This is a test message", "sound" => 'default')));
$message = json_encode(array( "default" => "This is a test message", "APNS" => $apns_payload));
For Android device, use like this
$gcm_payload = json_encode(array("data" => array("message" => "This is a test message", "sound" => 'default')));
$message = json_encode(array("default" => "This is a test message", "GCM" => $gcm_payload));
And finally, publish with your AWS SNS device ARN like below, TargetArn gets changed based on device token and platform
If iOS,
$target_arn = "arn:aws:sns:us-east-1:757730885501:endpoint/APNS/.....";
If Android,
$target_arn = "arn:aws:sns:us-east-1:757730885501:app/GCM/.....";
$sns->publish(array(
'TargetArn' => $target_arn,
'Message' => $message,
'MessageStructure' => 'json'
));
If you need to play the default sound in the device, you can set it as default, or else you can also use like ‘sound’ => ‘doorbell.caf’.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With