繁体   English   中英

phonegap构建:未收到ios推送通知

[英]phonegap build: Not receiving ios push notifications

我有一个简单的phonegap应用程序来测试“推送通知”。 我使用phonegap构建来构建应用程序,然后使用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的服务器,我叫他们启用了端口,现在工作正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM