Apple Push Notification with PHP, iphone does not recieve, what does possibility cause this happen?
here, is my coding on linux server.
$ctx = stream_context_create();
strea开发者_开发百科m_context_set_option($ctx, 'ssl', 'local_cert', 'apns-prod.pem');
$apnsConnection = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
$deviceToken = "XXXX"; //no space
$message = "A new question has been posted";
$body = array();
$body['aps'] = array('alert' => $message);
$badge = 1;
$sound = 1;
if($badge)
{$body['aps']['badge'] = $badge;}
if($sound)
{$body['aps']['sound'] = $sound;}
$payload = json_encode($body);
$msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
echo $payload;
fwrite($apnsConnection, $msg);
fclose($apnsConnection);
It happens, if your hosting server doesn't open the port:2195 or 2196.
I found the same problem. I guess Apple is not sending the push for some error. So I solved it like this: When the iPhone receives the push it goes back to the server and updates the GetPush column in the table. As long (or maybe three times) as this GetPush column is not set the server will ask the Apple server to send the push.
精彩评论