Push notifications are messages that allow an app to notify of a message similar to how a text message pops up on your screen with a sound.Code for Android ,Iphone API push notification is given below by using urban airship
Android Push Notification
$apiKey = 'XXXXXXXXXXXXXXX';
// Device Token
$token = 'XXXXXXXXXXXXXXXX';
// Message that has to be sent on device
$message ='Hello World! My test notification.';
// Additional data or parameter if required to send along with message
$any = 'test';
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$fields = array('registrationids' => $token,'data' => array("message" => $message,"any"=>$any));
$headers = array('Authorization: key=' . $apiKey,'Content-Type: application/json');
// Open connection
$ch = curlinit();
// Set the url, number of POST vars, POST data
curlsetopt( $ch, CURLOPTURL, $url );
curlsetopt( $ch, CURLOPTPOST, true );
curlsetopt( $ch, CURLOPTHTTPHEADER, $headers);
curlsetopt( $ch, CURLOPTRETURNTRANSFER, true );
curlsetopt($ch, CURLOPTSSLVERIFYPEER, false);
curlsetopt($ch, CURLOPTPOSTFIELDS, jsonencode( $fields ));
// Execute post
$result = curlexec($ch);
// Close connection
curlclose($ch);
$errchk = jsondecode($result);
0 Comment(s)