Reputation: 45
I need to implement a web app that consists in publishing events with the option of send notifications to subscribed people. How can I use the codename one libraries from a Web App?
Another question: When a cell phone receive the notification, can the application be opened in a specific window, in this case, the window which contain the event description?
Thank you in advance.
Upvotes: 1
Views: 311
Reputation: 7483
If your web app server is running php, you can use CURL
to send push notifications to devices. You can easily do the same with other languages. See below sample php code I used.
Shai mentioned recently that you can include some hidden payload in your push message. You can add some variables to this data which you'll check and use to open the necessary form.
PHP sample code:
$cloudServerURL = "https://push.codenameone.com/push/push";
$token = "Your_Developer_token"; //Can be found under account tab of Dashboard
$auth = "Google_Push_Key";
$certPassword = "Your_Certificate_Password";
$cert = "https://www.dropbox.com/path_to_your_iOS_cert/MyAppDevPush.p12?dl=1"; //Test
//Note the 'dl=1', this will download the certificate, instead of opening it.
//$cert = "https://www.dropbox.com/path_to_your_iOS_cert/MyAppProPush.p12?dl=1"; //Live
$production = "false"; //Test
//$production = "True"; //Live
$burl = "";
$bbAppId = "";
$bbPass = "";
$bbPort = "";
$device = 'device_key';
$type = "3"; //Or other types like (2, 101) as required
$body = "Hello world";
$arguments = 'token=' . $token . '&device=' . $device . '&type=' . $type . '&auth=' . $auth . '&certPassword=' . $certPassword . '&cert=' . $cert . '&body=' . $body . '&burl=' . $burl . '&bbAppId=' . $bbAppId . '&bbPass=' . $bbPass . '&bbPort=' . $bbPort . '&production=' . $production;
$ch = curl_init($cloudServerURL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $arguments);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
$response = unserialize(curl_multi_getcontent($ch));));
curl_close($ch);
Upvotes: 1