Question

I am working in a Android PhoneGap app where i need to use push notification by Urban Airship. I integrated(Development+Debug) Urban Airship push notification in my app and send test push from Urban Airship website and receive push to all device successfully.

But i need to send push notification from my windows(IIS installed) server(push text and sent time will vary upon server time). I want to send push text according to my schedule task. Schedule task is complete by PHP code.

So,any clue or idea how can i send push notification from my sever with appropriate schedule?

Thanks in advance.

Was it helpful?

Solution

If you can run PHP on your server, following this documentation should get you there - Urban Airship Simple PHP I have used it and it works great!

You would need to enclose most of it in a function which would then get called by your appropriate schedule.

Edit: added code

<?php
 define('APPKEY','XXXXXXXXXXXXXXX'); // Your App Key
 define('PUSHSECRET', 'XXXXXXXXXXXXXXX'); // Your Master Secret
 define('PUSHURL', 'https://go.urbanairship.com/api/push/');

 $contents = array();
 $contents['badge'] = "+1";
 $contents['alert'] = "PHP script test";
 $contents['sound'] = "cat.caf";
 $notification = array();
 $notification['ios'] = $contents;
 $platform = array();
 array_push($platform, "ios");

 $push = array("audience"=>"all", "notification"=>$notification, "device_types"=>$platform);

 $json = json_encode($push);
 echo "Payload: " . $json . "\n"; //show the payload

 $session = curl_init(PUSHURL);
 curl_setopt($session, CURLOPT_USERPWD, APPKEY . ':' . PUSHSECRET);
 curl_setopt($session, CURLOPT_POST, True);
 curl_setopt($session, CURLOPT_POSTFIELDS, $json);
 curl_setopt($session, CURLOPT_HEADER, False);
 curl_setopt($session, CURLOPT_RETURNTRANSFER, True);
 curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type:application/json', 'Accept: application/vnd.urbanairship+json; version=3;'));
 $content = curl_exec($session);
 echo "Response: " . $content . "\n";

 // Check if any error occured
 $response = curl_getinfo($session);
 if($response['http_code'] != 202) {
     echo "Got negative response from server: " . $response['http_code'] . "\n";
 } else {

     echo "Wow, it worked!\n";
 }

 curl_close($session);
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top