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

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

问题描述

我有一个包含以下内容的 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 错误:

警告:stream_socket_client() [function.stream-socket-client]:无法设置本地证书链文件`/var/www/vhosts/thissite.com/httpdocs/prod.pem';检查您的 cafile/capath 设置是否在第 19 行的/var/www/vhosts/thissite.com/httpdocs/pushMessageLive.php 中包含您的证书及其颁发者的详细信息

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-socket-client]:无法在第 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-socket-client]:无法在第 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-socket-client]:无法连接到/var/www/vhosts/thissite 中的 ssl://gateway.sandbox.push.apple.com:2195(未知错误).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

推荐答案

我遇到了同样的问题.您必须与 Apple 的 Push Notification Server 建立持久的套接字连接.我已经为一个名为 pyapns 的 python 守护进程编写了一个教程(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:

http://www.how2s.org/index.php/How_to_get_started_with_Apple_Push_Notifications_iPhone_for_for_iPhone_or_iPhone_Touch

http://www.how2s.org/index.php/How_to_get_started_with_Apple_Push_Notifications_for_iPhone_or_iPhone_Touch

假设您正在运行 Debian 并且具有安装所需软件包(例如 python-twisted、libcurl4-openssl-dev 等)的 root 访问权限,则此方法有效.

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天全站免登陆