Support Topics Documentation Slack YouTube Blog

PHP Push notification is going to all devices , even we target specific devices


(Jaymin Gajjar) #1

Hello,
We are using PHP Library to sending notifications to android/ios devices from our Web Application.
we want to send notification only to particular devices , but each time it sends push notification to all devices even if setPushPolicy(“ONLY”); is written.
Here is our code :
$pushid1 and $pushid2 are two device’s push id’s given by backendless , we want to send notification to only these device , but it send to all.
Please help.

$publish_options = new PublishOptions();
$publish_options->putHeader( "android-ticker-text", $message );
$publish_options->putHeader( "android-content-title", "PUSH_NOTIFICATION_TITLE");
$publish_options->putHeader( "android-content-text", $message );
$publish_options->putHeader( "action","new_post" );
$publish_options->putHeader( "id", "12" );
$delivery_options = new DeliveryOptions();
$delivery_options->addPushSinglecast( $pushid1 );
$delivery_options->addPushSinglecast( $pushid2 );
$delivery_options->setPushPolicy("ONLY");
$status = Backendless::$Messaging->publish( $message,$publish_options );

Thanks in advance.
Jaymin


(Denys Konakhevych) #2

Hi Jaymin,

Maybe i am wrong, but it seems delivery_options was not passed to method publish. Please, try

$status = Backendless::$Messaging->publish( $message,$publish_options,$delivery_options );

Regards,

Denys


(Jaymin Gajjar) #3

Hi ,

Thank you for quick reply , i tried that too but still it is not working
Here is my update code :

$publish_options = new PublishOptions();
$publish_options->putHeader( "android-ticker-text", $message );
$publish_options->putHeader( "android-content-title", "PUSH_NOTIFICATION_TITLE");
$publish_options->putHeader( "android-content-text", $message );
$publish_options->putHeader( "action","new_post" );
$publish_options->putHeader( "id", "12" );
$delivery_options = new DeliveryOptions();
$delivery_options->addPushSinglecast( $pushid1 );
$delivery_options->addPushSinglecast( $pushid2 );
$delivery_options->setPushPolicy("ONLY");
$status = Backendless::$Messaging->publish( $message,$publish_options,$delivery_options );

Thanks.


(Jaymin Gajjar) #4

it did not worked, please any other help would be great , as we are stuck here :frowning: