我使用以下代码发送iphone通知。代码工作正常。通知在7.之前转到旧版本操作系统。但是通知不会发送到新的操作系统。它没有显示任何错误。它显示已成功发送的消息但消息未发送。
<?php
error_reporting(E_ALL);
$message="Welcome to 2015";
$passphrase = 'venky';
$badge = 1;
$ck=realpath("ck.pem");
////////////////////////////////////////////////////////////////////////////////
///integrating the ck.pem file to APN's
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $ck);
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); */
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $error,$errorString, 60, STREAM_CLIENT_CONNECT, $ctx);
if (!$fp)
{
//return "Failed to iOS connect error: $err $errstr".PHP_EOL;
print "Failed to connect $error $errorString";
//exit("Failed to connect: $err $errstr" . PHP_EOL);
}
$body['aps'] = array('alert' => $message,'badge' => $badge,'sound' => 'default');
// Encode the payload as JSON
$payload = json_encode($body);
$deviceToken = "a74cad7dbf592073de007c7b830c63889b18610534bbe35ceb989c7bfb30a3eb";
// 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) {
$f+=1;
}
else
{
$s+=1;
}
// Close the connection to the server
//running feedback service
stream_context_set_option($ctx, 'ssl', 'local_cert',$ck);
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$apns = stream_socket_client('ssl://feedback.push.apple.com:2196', $error, $errorString, 5, STREAM_CLIENT_CONNECT, $ctx);
if(!$apns)
{
//echo "ERROR $errcode: $errstr\n";
return;
}
//else echo 'APNS FEEDBACK CONNECTION ESTABLISHED...<br/>';
$feedback_tokens = array();
$count = 0;
$feedback_tokens = array();
//and read the data on the connection:
while(!feof($apns)) {
$data = fread($apns, 38);
if(strlen($data)) {
$feedback_tokens[] = unpack("N1timestamp/n1length/H*devtoken", $data);
}
}
fclose($apns);
if($s>=1)
{
echo 'Notification sent successfully to '.$s.' iPhone Devices out of '.$s;
}
else
echo 'Notification not sent to '.$f.' iPhone Devices out of '.$f;
fclose($fp);
?>
我收到'通知已成功发送到1台iPhone设备1'成功消息。但通知不会去新的iphone os设备。请帮帮我