APNs notification failure...

Posted by Kamal Challa on Stack Overflow See other posts from Stack Overflow or by Kamal Challa
Published on 2009-09-30T11:16:07Z Indexed on 2011/01/12 9:54 UTC
Read the original article Hit count: 353

Filed under:
|

Hi ,

i tried the following code (PHP)

$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apple_push_notification_production.pem';

$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
if($apns)
{
	echo "Connection Established<br/>";
	$deviceToken = '**********';//masked

	$body = array();
	$body['aps'] = array(’alert’ => "test message");
	//$body['aps']['badge'] = 1;

	$payload = json_encode($body);


	$apnsMessage = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
	print "sending message :" . $apnsMessage . "<br/>";
	print "sending payload :" . $payload . "<br/>";
	fwrite($apns, $apnsMessage);

}
else
{	
	echo "Connection Failed";

	echo $errorString;
	echo $error;
}
socket_close($apns);
fclose($apns);

reply is Connection Established sending message :?? d^÷Îå0ZCd%1ÄuwOOYš'ÊÈ}ârðm¾Í?,{"aps":{"\u2019alert\u2019":"test message"}} sending payload :{"aps":{"\u2019alert\u2019":"test message"}}

But am not able to get the notification

any help?

© Stack Overflow or respective owner

Related posts about php

Related posts about apns