Kyri33
Kyri33

Reputation: 599

Codename one push notifications with php issue

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' 
 =>     
'[email protected]', '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));
?>

Upvotes: 8

Views: 223

Answers (1)

Kyri33
Kyri33

Reputation: 599

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' =>    
'[email protected]', '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));

 ?>

Upvotes: 3

Related Questions