Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ruby中的APNs错误处理_Ruby_Apple Push Notifications_Tcpsocket - Fatal编程技术网

ruby中的APNs错误处理

ruby中的APNs错误处理,ruby,apple-push-notifications,tcpsocket,Ruby,Apple Push Notifications,Tcpsocket,我想批量向apple设备发送通知(例如,批量发送1000个设备令牌)。Ant看来我不能确定这条消息是否已经发送给了APNs 以下是代码示例: ssl_connection(bundle_id) do |ssl, socket| device_tokens.each do |device_token| ssl.write(apn_message_for device_token) # I can check if there is an error response from

我想批量向apple设备发送通知(例如,批量发送1000个设备令牌)。Ant看来我不能确定这条消息是否已经发送给了APNs

以下是代码示例:

ssl_connection(bundle_id) do |ssl, socket|
  device_tokens.each do |device_token|
    ssl.write(apn_message_for device_token)

    # I can check if there is an error response from APNs
    response_has_an_error = IO.select([socket],nil,nil,0) != nil
    # ...
  end
end
主要问题是在建立ssl_连接后网络是否关闭

ssl.write(...)
永远不会出错。有没有办法检查连接是否仍然有效

第二个问题是来自APN的ssl.write和ready错误回答之间的延迟。在发送最后一条消息后,我可以将超时参数传递给IO.select。也许等待几秒钟就可以得到1000个批次,但是如果我必须为不同的捆绑ID发送1000条消息呢?

在,我们使用一个名为grocer的gem来处理我们与苹果的通信,我们遇到了类似的问题。我们找到的解决方案是在每次写入之前使用套接字的
read\u non\u block
方法来检查套接字上是否存在表示错误的传入数据

这使得逻辑有点可笑,因为如果没有数据可读取,则
read_non_block
抛出
IO::WaitReadable
。因此,我们调用
read_non_block
和catch
IO::WaitReadable
,然后继续正常操作。在我们的案例中,抓住例外是一个令人高兴的案例。您可以使用类似的方法,而不是使用
IO。选择(…)

需要注意的一个问题是,苹果可能不会立即响应,在失败通知和从套接字读取之间发送的任何通知都将丢失

您可以在上看到我们在生产中使用的代码