I am following this tutorial to set up a push notifications >> http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12
Yet push notifications do not come to my phone. The phone registers succesfully. The provider connects to apns succesfully and sends the message to the registered deviceToken. Yet no notification arives.
Tried to follow the tutorial for a second time from the begining and still the same result.
At third time I tested my ck.pem files like this
openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert ck.pem -debug
And got this return.
Verify return code: 20 (unable to get local issuer certificate)
Searched for a while on how to resolve this, yet nothing helped. I don't know if this is why phone fails to recieve messages but it could be the case. Anybody knows how can i solve this? Or maybe other things to check ? I'v done the tutorial step by step for the third time, and don't know what to look for. APNS doesn't return any error-status after sending message.
Provider posting code in php>>
<?php
$deviceToken = 'c8964c75e5d404f029e2d599d094a2114d219bdb95750ae6501d6f0ce6a3c3b4';
$passphrase = 'DEADFFFF';
$message = 'Check';
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
fclose($fp);
Application is in debug mode, server certificate is also for development Running the code gives Message successfully delivered.