My ability to send Push Notifications to my app was working perfectly; one day, the devices just stopped receiving them. I've tested my development and production certs, and both connect to the APNS perfectly, and tell me my notification was sent. That said, no device (not even the one specified via Device Token) receives the notification?
Here's the PHP I'm using to connect to APNS & send the message:
PushNotify.php
<?php
$apnsServer = 'api.sandbox.push.apple.com:443';
/* Make sure this is set to the password that you set for your private key
when you exported it to the .pem file using openssl on your OS X */
$privateKeyPassword = '0000001';
/* Put your own message here if you want to */
$message = 'Hey there it's today';
/* Pur your device token here */
$deviceToken =
'2374387438mytoken';
/* Replace this with the name of the file that you have placed by your PHP
script file, containing your private key and certificate that you generated
earlier */
$pushCertAndKeyPemFile = 'apns-development.pem';
$stream = stream_context_create();
stream_context_set_option($stream,
'ssl',
'passphrase',
$privateKeyPassword);
stream_context_set_option($stream,
'ssl',
'local_cert',
$pushCertAndKeyPemFile);
$connectionTimeout = 20;
$connectionType = STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT;
$connection = stream_socket_client($apnsServer,
$errorNumber,
$errorString,
$connectionTimeout,
$connectionType,
$stream);
if (!$connection){
echo "Failed to connect to the APNS server. Error no = $errorNumber<br/>";
exit;
} else {
echo "Successfully connected to the APNS. Processing...</br>";
}
$messageBody['aps'] = array('alert' => $message,
'sound' => 'default',
'badge' => 2,
);
$payload = json_encode($messageBody);
$notification = chr(0) .
pack('n', 32) .
pack('H*', $deviceToken) .
pack('n', strlen($payload)) .
$payload;
$wroteSuccessfully = fwrite($connection, $notification, strlen($notification));
if (!$wroteSuccessfully){
echo "Could not send the message<br/>";
}
else {
echo "Successfully sent the message<br/>";
}
fclose($connection);
?>
Again, a success message is returned, but no notification is received :/ Any help is appreciated, this one is making me pull my hair out! I've recreated the certs at least 5 times (even though I've confirmed that they are connecting to the APNS).