phonegap build:没有收到ios推送通知

时间:2013-10-16 00:13:58

标签: ios cordova apple-push-notifications phonegap-build

我有一个简单的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);

?>

1 个答案:

答案 0 :(得分:1)

我也遇到过这个问题,但我已经得到了解决方案。将通知发送到设备您必须在防火墙中启用2195端口。只需连接您的服务器公司即可启用此端口。我有来自hostgator的服务器我称他们启用了端口,现在工作正常。

相关问题