iPhone SDK推送通知随机失败 [英] iPhone SDK Push notification randomly fails

查看:482
本文介绍了iPhone SDK推送通知随机失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下内容的关于发展ceritficates完美的作品PHP文件,但是当我切换到生产证书PHP错误,并给出了下面的消息,但它只做时这50%左右。另外50%它的作品。任何人都知道为什么会是这样吗?

I have a PHP file with the following content that works perfectly on development ceritficates, but when I switch to a production certificate the PHP errors and gives the below message, but it only does this about 50% of the time. The other 50% it works. Anyone know why this might be happening?

<?php
// masked for security reason 
$deviceToken = 'xxxxxx'; // jq

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', dirname(__FILE__)."/prod.pem");

$number = 5;

$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
if (!$fp) {
  print "Failed to connect $err $errstr\n";
}
else {
  print "Connection OK\n";
  $msg = $_GET['msg'];
    $payload['aps'] = array('alert' => $msg, 'badge' => 1, 'sound' => 'default');
    $payload = json_encode($payload);

  $msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
  print "sending message :" . $payload . "\n";
  fwrite($fp, $msg);
  fclose($fp);
}
?>

PHP的错误:

The PHP error:

警告:在stream_socket_client()[function.stream插槽客户端]:无法设置本地证书链文件'/var/www/vhosts/thissite.com/httpdocs/prod.pem';检查您的凭证档案错误/ capath设置包括您的证书及其/var/www/vhosts/thissite.com/httpdocs/pushMessageLive.php第19行发行的细节

Warning: stream_socket_client() [function.stream-socket-client]: Unable to set local cert chain file `/var/www/vhosts/thissite.com/httpdocs/prod.pem'; Check that your cafile/capath settings include details of your certificate and its issuer in /var/www/vhosts/thissite.com/httpdocs/pushMessageLive.php on line 19

警告:在stream_socket_client()[function.stream插槽客户端]:未能在第19行创建一个/var/www/vhosts/thissite.com/httpdocs/pushMessageLive.php SSL句柄

Warning: stream_socket_client() [function.stream-socket-client]: failed to create an SSL handle in /var/www/vhosts/thissite.com/httpdocs/pushMessageLive.php on line 19

警告:在stream_socket_client()[function.stream插槽客户端]:失败,使第19行中/var/www/vhosts/thissite.com/httpdocs/pushMessageLive.php加密

Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in /var/www/vhosts/thissite.com/httpdocs/pushMessageLive.php on line 19

警告:在stream_socket_client()[function.stream插槽客户端]:无法连接到SSL://gateway.sandbox.push.apple.com:2195在/ var(未知的错误)/网络/虚拟主机/ thissite .COM / httpdocs资料/ pushMessageLive.php第19行
无法连接0

Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /var/www/vhosts/thissite.com/httpdocs/pushMessageLive.php on line 19 Failed to connect 0

推荐答案

我有同样的问题。你必须要与苹果推送通知服务器的持久套接字连接。我已经写了一个教程叫蟒蛇守护的 pyapns (http://github.com/samuraisam/pyapns),它的工作对我非常好:

I had the same issue. You have to make a persistent socket connection with Apple's Push Notification Server. I've written up a tutorial for a python daemon called pyapns (http://github.com/samuraisam/pyapns) which worked very well for me:

<一个href=\"http://www.how2s.org/index.php/How_to_get_started_with_Apple_Push_Notifications_for_iPhone_or_iPhone_Touch\" rel=\"nofollow\">http://www.how2s.org/index.php/How_to_get_started_with_Apple_Push_Notifications_for_iPhone_or_iPhone_Touch

这工作假设您正在运行Debian以及有root权限来安装所需的软件包,如蟒蛇绞,libcurl4-的OpenSSL开发等。

This works assuming you are running Debian and have root access to install the required packages such as python-twisted, libcurl4-openssl-dev etc.

这篇关于iPhone SDK推送通知随机失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆