发送到 APNS 套接字服务器的最大设备数 [英] Max number of devices to send to APNS socket sever

查看:26
本文介绍了发送到 APNS 套接字服务器的最大设备数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们运行了将近一年的推送通知脚本突然停止工作了.该脚本执行以下操作:

Our push notification script that has worked for almost a year has suddenly stopped working. The script does the following:

  1. 查询数据库以获取 iPhone 设备令牌列表

  1. Queries a DB for a list of iPhone device tokens

打开与 Apple 的实时 APNS 服务器的 SSL 套接字连接

Opens an SSL socket connection to Apple's live APNS server

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', $apnsCert);
stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);
$fp = stream_socket_client($apnsHost, $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);

  • 使用 255 字节大小的消息创建有效负载

  • creates a payload with a 255 byte sized message

    $payload = '{
      "aps": {
         "alert": "' . $message . '",
         "badge": 1,
         "sound": "default"
      }
    }';
    

  • 遍历每个设备并将有效负载写入打开的连接.

  • Loops through each device and writes the payload to the open connection.

    $msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
    fwrite($fp, $msg);
    

  • 然后关闭连接.

  • The connection is then closed.

    fclose($fp);
    

  • 所以我的问题是——脚本中没有任何改变,但改变的是数据库的大小.我创建了一个 Web 界面,允许用户向所有 iphone 设备发送有效负载,当它运行时,只需几秒钟即可发送/加载.是否有可能是数据库中的设备数量(大约 3500)造成了问题?

    So my question is this-- nothing in the script has changed, but what HAS changed is the size of the database. I created a web interface that allows a user to send a payload to all iphone devices and when it runs it only takes a few seconds to send/load. Is it possible though that the number of devices in the DB (around 3500) is creating the problem?

    当我写入套接字时,我可以向其发送推送通知的最大设备数量是多少?是否存在最大值或限制?

    What is the maximum number of devices that I can I send a push notification to when I write to the socket? Does a max or limit exist?

    推荐答案

    问题不在于发送到 APNS 的设备数量.问题原来是苹果改变了他们的 API.您现在需要检查每个设备以查看它是否仍然有效(即,如果他们拒绝推送通知,设备是否删除了应用程序等).如果设备不再接受来自您的应用的推送通知,而您仍然向其发送通知,Apple 会立即断开与您的 APNS 套接字的连接.我现在有一个每天运行一次程序的 cronjob,它检查并删除我的数据库中不再接受推送通知的任何设备(Apple 有这个列表).但要小心——一旦您从 Apple 提取禁用设备 ID 列表,Apple 就会将其从其服务器中删除,您将永远无法再次提取它.

    The problem wasn't the number of devices to sent to APNS. The problem turned out to be that Apple changed their API. You now need to check every single device to see if it's still valid (ie. if they are denying push notificaitons, if the device deleted the app, etc.). If the device no longer accepts push notifications from your app and you send one to it anyways, Apple immediately drops the connection to your APNS socket. I now have a cronjob that runs a program once a day that checks and deletes any devices from my database that no longer accept push notifications (Apple has this list). But be careful -- once you pull the list of disabled device ids from Apple, Apple deletes it from their server and you can never pull it again.

    您还需要更新推送通知代码以检查连接是否曾中断.当连接断开时,程序需要重新建立连接并再次尝试推送.

    You also need to update your push notification code to check if the connection is ever dropped. When the connection is dropped, the program needs to reestablish the connection and try to push again.

    这篇关于发送到 APNS 套接字服务器的最大设备数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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