iOS的推送通知连接失败错误 [英] iOS push notification connection failed error

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

问题描述

我试图通过PHP发送推送通知的iPhone应用程序。因此,iOS开发者给我的PEM文件。我要求托管服务器打开 gateway.sandbox.push.apple.com:2195 ,他们已经打开的端口。但是,当我尝试发送推送通知,我收到以下错误。我的code看起来像

I am trying to send a push notification in iOS application via php. So the iOS developer give me the pem file. I requested the hosting server to open gateway.sandbox.push.apple.com:2195 and they have opened the port. But when I am trying to send push notification, I am getting the following error. My code looks like

$deviceToken='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';

$passphrase="";

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', '/home/sitename/public_html/push/ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

$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 amarnew: $err $errstr" . PHP_EOL);

echo 'Connected to APNS' . PHP_EOL;

收到以下错误

Failed to connect amarnew: 0 

所以,我想通过telnet连接到苹果,那结果是

So I tried the connection to apple via telnet, that result is

root@uio3-i [~]# telnet gateway.sandbox.push.apple.com 2195
Trying XX.XXX.XXX.XX...
Connected to gateway.sandbox.push.apple.com.
Escape character is '^]'.
^\q
^]
telnet> q
Connection closed.
root@uio3-i [~]#

由于我是新来这个,我只是在这里被卡住。请任何一个帮助我

As I am new to this, I just stucked here. Please any one help me

在此先感谢

推荐答案

听起来像是你的证书/密钥.pem文件已损坏,重新生成。我只是刚刚推自己的工作,所以我知道这是一个棘手的话题。

Sounds like your certificate/key pair .pem file is corrupt, regenerate it. I only just got push working myself so I know it's a tricky topic.

而不是简单的telnet(这只能证明连接正常),而不是从终端运行此命令,以确定证书和密钥是有效的。

Rather than simply telnet (which only proves connectivity is OK), instead run this command from terminal to determine if the Cert and Key are valid.

openssl s_client -connect gateway.sandbox.push.apple.com:2195 
-cert cert.pem -key key.pem

您应该看到一大堆的输出,这是OpenSSL的让你知道什么是引擎盖下怎么回事。

You should see a whole bunch of output, which is openssl letting you know what is going on under the hood.

如果连接成功,你应该可以键入几个字符。当你preSS输入,服务器应该断开连接。如果有建立连接有问题,OpenSSL的会给你一个错误消息,但您可能必须通过输出向上滚动才能找到它。

If the connection is successful, you should be able to type a few characters. When you press enter, the server should disconnect. If there was a problem establishing the connection, openssl will give you an error message but you may have to scroll up through the output to find it.

不管怎样,至少你会知道,如果你的证书/密钥对都不错。

Either way at least you will know if your cert/key pair are good.

在生产,你必须使用一个串联的证书/密钥对的 - 如果你没有原始的密钥和证书,您将需要从开发得到这个测试上述

In production you have to use a concatenated cert/key pair - If you don't have the original key and cert you will need to get this from the dev to test the above.

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

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