简体   繁体   English

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

[英]phonegap build: Not receiving ios push notifications

I have a simple phonegap app to test Push Notification. 我有一个简单的phonegap应用程序来测试“推送通知”。 I use phonegap build to build the app and then install the app on my iphone using itunes. 我使用phonegap构建来构建应用程序,然后使用iTunes在iPhone上安装该应用程序。 The registration of the push notification was successful with the production push certificate pem. 推送通知的注册成功,并带有生产推送证书pem。 But I couldn't receive any push notifications after executing the php script below. 但是执行下面的php脚本后,我没有收到任何推送通知。 The script itself runs fine without any errors. 脚本本身运行良好,没有任何错误。 Any ideas what could go wrong? 有什么想法可能出问题吗?

   // 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);

?>

I have also gone through this problem but i have got the solution. 我也经历了这个问题,但我已经找到了解决方案。 To send the notifications to device You have to enable the 2195 port in firewall. 将通知发送到设备您必须在防火墙中启用2195端口。 Just conatct your server company to enable this port. 只需连接您的服务器公司以启用此端口。 I have server from hostgator i called them they enabled the port and now working fine. 我有来自hostgator的服务器,我叫他们启用了端口,现在工作正常。

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

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