Продолжая ответ emagic, это мой фрагмент php-кода:
private $fp;
private function connect(){
$apnsHost = 'gateway.push.apple.com';
$apnsCert = 'certs/cert.pem';
$apnsPort = 2195;
$pass = "blah";
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
stream_context_set_option($streamContext, 'ssl', 'passphrase', $pass);
$this->fp = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $streamContext);
if (!$this->fp) return("Failed to connect: $err $errstr<br>");
echo 'Connected to APNS<hr />';
}
private function send(){
$this->connect();
foreach($pushes as $push) {
$payload['aps'] = array('alert' => $push->text, 'badge' => 0, 'sound' => 'default');
$payload2 = json_encode($payload);
$msg = chr(0) . pack('n', 32) . pack('H*', $push->token) . pack('n', strlen($payload2)) . $payload2;
try {
$result = fwrite($this->fp, $msg, strlen($msg));
}
catch (\Exception $e) {
fclose($this->fp);
echo('Error sending payload: ' . $e->getMessage());
sleep(5);
$this->connect();
}
}
}