I have been trying for the past how long to figure out how to go from the sandbox APNS to production APNS. Below is the PHP code used to send notifications to my app.
$passphrase = 'SomethingStrong';
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $_SERVER['DOCUMENT_ROOT'] . '/ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
{
//return json_encode(array('response' => 'connection_fail'));
}
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
return json_encode(array('response' => 'unsuccessful'));
else
return json_encode(array('response' => 'successful'));
fclose($fp);
This whole thing works when I keep the URL ssl://gateway.sandbox.push.apple.com:2195
, but when I when I change it to ssl://gateway.push.apple.com:2195
no notifications come through my app, yet PHP outputs that it was sent successfully.
I'm code-signing with the development certificates.
I'm new to notifications and have never used them before, so sorry if I'm doing something really obvious. Thanks.