简体   繁体   English

服务器端Apple Push Notification

[英]Server-side Apple Push Notification

I need a little help in implementing push notification in iOS. 在iOS中实现推送通知时,我需要一些帮助。 I am using Swift. 我正在使用Swift。

I successfully created Push certificate and key (.pem). 我成功创建了推送证书和密钥(.pem)。 I am able to retrieve the deviceToken. 我能够检索deviceToken。 And I was able to send notification to my device via APN Tester Free app. 而且我能够通过APN Tester Free应用程序将通知发送到我的设备。 So, basically push notification is working in my local computer. 因此,基本上,推送通知在我的本地计算机上有效。

I found this tutorial and picked up the PHP file and uploaded it to the server, together with my .PEM file. 我找到了本教程,并选择了PHP文件并将其与.PEM文件一起上传到服务器。 But when I try to open sample.com/newspush.php, I get Service Unavailable. 但是,当我尝试打开sample.com/newspush.php时,出现服务不可用的情况。

I also tried other tutorial (I could not remember the link). 我还尝试了其他教程(我不记得链接了)。 But I am getting: Failed to connect to the APNS server. 但是我得到了:无法连接到APNS服务器。 Error = Connection timed out 错误=连接超时

This is because your server didn't allow access.Set up the permission wrong on the folder that had the certificate file. 这是因为您的服务器不允许访问。在具有证书文件的文件夹上设置错误的权限。 Give chmod 755 permission to that folder which contains .pem file. chmod 755授予包含.pem文件的文件夹的权限。 This will fix your problem. 这将解决您的问题。

Or may be your server closed the 2195 port. 或者可能是您的服务器关闭了2195端口。 So make sure that port open.To check that can run this code in you server. 因此,请确保该端口处于打开状态。要检查该端口是否可以在服务器中运行此代码。

 telnet gateway.push.apple.com 2195

If your server has a problem it will show something like this :- 如果您的服务器有问题,它将显示以下内容:

Trying 17.172.233.36...
telnet: connect to address 17.172.233.36: Connection refused

So then you solve this problem by opening the 2195 port 因此,您可以通过打开2195端口来解决此问题

If your server already open the port it will show :- 如果您的服务器已经打开端口,它将显示:-

 -bash-3.2# telnet gateway.push.apple.com 2195

  Trying 17.149.38.141...
  Connected to gateway.push.apple.com (17.149.38.141).
  Escape character is '^]'.
  Connection closed by foreign host.

Hope that this will help you! 希望对您有所帮助!

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

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