Friday, April 22, 2016

Codename one push notifications with php issue

Leave a Comment

I've enabled push notifications in my app, added the build hints, registered the api on the play developer console, created and loaded the apple certificates on my server. When I test the app on a device it successfully registers for push notifications. However my issue comes in with trying to actually send a push notification. I want it to send through PHP. I use this code which is taken straight from the developer guide. However this does not work... Is it a problem with my code or did I do something wrong in the enabling push notifications process.

<?php  include("config.php");  $args = http_build_query(array( 'certPassword' => 'XXXXXXXX', 'cert'  =>    'http://kyven.co.za/mibrand/certificate/XXXX.p12', 'production' => false, 'device' => null, 'packageName' => 'za.co.bonyelo.mibrand', 'email'   =>      'kyri88@gmail.com', 'type' => 1, 'auth' => 'XXXXXXXXXXXXXXXXXXXXXXXXXX', 'body' => 'Test')); $opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded',    'content'      => $args ) ); $context = stream_context_create($opts); $response = file_get_contents("https://codename-     one.appspot.com/sendPushMessage", false, $context);  die(json_encode($response)); ?> 

2 Answers

Answers 1

Got it. This is the code I used

<?php  include("config.php");  $args = http_build_query(array('token' => 'XXXXXXXXXXXXXXXXXXX', 'certPassword' => 'XXXXXXXX', 'cert' =>      'http://XXXXXXX/XXXXX/XXXXX/Certificates.p12', 'production' => false, 'device' => 'cn1-ios-XXXXXXXXXXXXXXXXXXXXXXXX',  'packageName' => 'za.co.bonyelo.mibrand', 'email' =>     'kyri88@gmail.com', 'type' => 1, 'auth' => 'XXXXXXXXXXX', 'body' => 'EAT MY BALLS'));  $opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded',    'content' => $args ) ); $context = stream_context_create($opts); $response =    file_get_contents("https://push.codenameone.com/push/push", false,    $context);  die(json_encode($response));   ?> 

Answers 2

I don't know PHP so I can't really help with the code. Notice that this is old code that was contributed by a 3rd party and it refers to the old push servers.

You need to write new code based on the current documentation which we provide in Java. You can contribute to that documentation effort in our wiki.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment