我有一个简单的 phonegap 应用程序来测试推送通知。我使用 phonegap build 构建应用程序,然后使用 itunes 在我的 iPhone 上安装该应用程序。使用生产推送证书 pem 成功注册了推送通知。但是执行下面的php脚本后我收不到任何推送通知。脚本本身运行良好,没有任何错误。有什么想法会出错吗?
// This this a fake device id:
$deviceToken = '9870h8v088bj29u080af894jj67klfgcv9mmm79k8e4l23456h908743n093e359';
// fake password:
$passphrase = '123456';
// Put your alert message here:
$message = 'New Message';
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
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);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default',
'badge' => '1'
);
// Encode the payload as JSON
$payload = json_encode($body);
// 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)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
// Close the connection to the server
fclose($fp);
?>
最佳答案
我也遇到过这个问题,但是我已经找到解决方案了。要将通知发送到设备,您必须在防火墙中启用 2195 端口。只需联系您的服务器公司以启用此端口。我有来自 Hostgator 的服务器,我称他们启用了端口,现在工作正常。
关于ios - 音隙构建 : Not receiving ios push notifications,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19393254/