I am using this tutorial to learn push notification.
First make sure that you're using:
then use the following code (been tested both dev & production)
"; // Some Device Token
// Notification content
$payload = array();
//Basic message
$payload['aps'] = array(
'alert' => 'testing 1,2,3..',
'badge' => 1,
'sound' => 'default',
);
$payload['server'] = array(
'serverId' => $serverId,
'name' => $serverName
);
// Add some custom data to notification
$payload['data'] = array(
'foo' => "bar"
);
$payload = json_encode($payload);
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
stream_context_set_option($streamContext, 'ssl', 'passphrase', "");
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
$deviceToken = str_replace(" ","",substr($device_token,1,-1));
echo $deviceToken;
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(mb_strlen($payload)) . $payload;
fwrite($apns, $apnsMessage);
//socket_close($apns);
fclose($apns);
?>