Push Notifications APNS suddenly stopped working- sandbox - php
I am working on a Iphone app that uses push notification.It was working fine earlier and suddenly stopped working. My php code is
<?php
$deviceToken = ''; // masked for security reason
// Passphrase for the private key (ck.pem file)
$pass = 'appendit';
// Get the parameters from http get or from command line
$message = $_GET['message'] or $message = $argv[1] or $message = 'Test Message';
$badge = (int)$_GET['badge'] or $badge = (int)$argv[2];
$sound = $_GET['sound'] or $sound = $argv[3];
// Construct the notification payload
$body = array();
$body['aps'] = array('alert' => $message);
if ($badge)
$body['aps']['badge'] = $badge;
if ($sound)
$body['aps']['sound'] = $sound;
/* End of Configurable Items */
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'apns-dev.pem');
// assume the private key passphase was removed.
stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
if (!$fp) {
print "Failed to connect $err $errstrn";
return;
}
el开发者_如何学JAVAse {
print "Connection OK \n";
}
$payload = json_encode($body);
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
print "sending message :" . $payload . "\n";
fwrite($fp, $msg);
fclose($fp);
?>
I am getting Connection OK sending message :{"aps":{"alert":"Test Message"}} while running from browser. Any idea what may be wrong there ?
Thanks
My guess is that your certificate has expired. I had an expired dev certificate and Apple just accepted the message without complaint, although it never arrived. When I updated the certificate the messages started arriving.
精彩评论