Reputation: 1
here, is my coding on linux server.
$ctx = stream_context_create();
stream_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);
Upvotes: 0
Views: 661
Reputation: 920
It happens, if your hosting server doesn't open the port:2195 or 2196.
Upvotes: 1
Reputation: 1082
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.
Upvotes: 0