Apple 推送通知服务 ( APNS ):反馈服务响应缺少字节?
我正在用 Ruby 编写一个推送通知系统。使用增强界面发送通知工作正常,从反馈服务消费根本不起作用。
我自己编写了从套接字读取的代码,如下所示:
context = OpenSSL::SSL::SSLContext.new
context.cert = OpenSSL::X509::Certificate.new(File.read(pem_path))
context.key = OpenSSL::PKey::RSA.new(File.read(rsa_path))
@socket = TCPSocket.new(host, port)
@ssl = OpenSSL::SSL::SSLSocket.new(@socket, context)
@ssl.connect
@socket.gets #read(38) has the same effect FWIW
但 APNS 反馈服务仅返回 37 个字节,而不是预期的 38 个字节,并且正如预期的那样,包混乱了。
我可以使用 Ruby APNS gem 复制错误(并为他们开了一张票 此处)。
我已将从 APNS 反馈服务收到的所有内容保存到一个文件中,这是我在尝试检查字节时得到的结果:
ruby-1.9.2-p290 :035 > while b = f.readbyte
ruby-1.9.2-p290 :036?> puts b
ruby-1.9.2-p290 :037?> end
21
3
1
0
32
23
35
236
232
217
53
172
143
54
130
39
157
247
205
233
231
245
140
111
104
199
214
159
60
107
169
175
42
172
57
31
160
如您所见,数组偏移了 1,应该如下所示:
有人遇到类似问题或可以看到我做错了什么吗?
谢谢
编辑@ 19/2011:
这似乎是 Ruby 套接字的问题。使用 java-apns lib 以下 Clojure 核心返回同一应用程序、证书的预期结果等等。
(def tokens (. (.. (APNS/newService)
(withCert "/Users/pcalcado/blah.p12" "blah")
withProductionDestination
build)
getInactiveDevices))
我看不到任何特别的由java完成-apns 或者我在 Ruby 中可能做错了什么。我不介意在这个系统中使用 Clojure,但现在我已经拥有了除了反馈之外的所有内容,并且已经在 MRI 上用 Ruby 编写并运行了 =/
I am writing a push notifications system in Ruby. Sending the notifications using the enhanced interface works fine, consuming from the Feedback Service is not working at all.
I wrote the code to read from the socket myself, something like this:
context = OpenSSL::SSL::SSLContext.new
context.cert = OpenSSL::X509::Certificate.new(File.read(pem_path))
context.key = OpenSSL::PKey::RSA.new(File.read(rsa_path))
@socket = TCPSocket.new(host, port)
@ssl = OpenSSL::SSL::SSLSocket.new(@socket, context)
@ssl.connect
@socket.gets #read(38) has the same effect FWIW
But the APNS Feedback Service returns only 37 bytes instead of the expected 38, and as expected the package is messes up.
I can replicate the error using the Ruby APNS gem (and openened a ticket for them here).
I've saved all I receive from the APNS Feedback Service to a file and here's what I get when trying to inspect the bytes:
ruby-1.9.2-p290 :035 > while b = f.readbyte
ruby-1.9.2-p290 :036?> puts b
ruby-1.9.2-p290 :037?> end
21
3
1
0
32
23
35
236
232
217
53
172
143
54
130
39
157
247
205
233
231
245
140
111
104
199
214
159
60
107
169
175
42
172
57
31
160
As you can see, the array is off by one, is should look like this:
Anyone had similar issues or can see what I am doing wrong?
Thanks
EDIT @ 19/2011:
This seems to be an issue with Ruby sockets. Using the java-apns lib the following Clojure core returns the expected result for the same application, certificates and etc.
(def tokens (. (.. (APNS/newService)
(withCert "/Users/pcalcado/blah.p12" "blah")
withProductionDestination
build)
getInactiveDevices))
I cannot see anything special being done by java-apns or what I could be doing wrong in Ruby. I wouldn't mind using Clojure for this system but now I have everything but Feedback already written and running in Ruby on MRI =/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我问自己...我们是否有可能必须从 @ssl 而不是 @socket 读取?
抱歉,我对 Ruby 编程有点不懂:)
编辑:
我确认你的问题是你需要从 SSL 套接字读取
看看这个提交: https://github.com/muccy/APNS/commit/4d62a3f33c4b31f7f81a0020aa70871232f46781
I asking myself... is it possible we have to read from @ssl instead of @socket?
Sorry but I am a bit n00b about Ruby programming :)
Edit:
I confirm you the problem is that you need to read from SSL socket
Look at this commit: https://github.com/muccy/APNS/commit/4d62a3f33c4b31f7f81a0020aa70871232f46781
看看 Josh Priddle 的 APND gem。我成功地使用了它,并相信它的核心功能(包括从 Apple 检索反馈)可以正常工作。如果没有别的原因,这是另一个代码示例(用 Ruby 编写)供您检查。
Have a look at the APND gem by Josh Priddle. I used it successfully, and believe its core functionality, which includes retrieving feedback from Apple, works as it should. If for nothing else, it's another code example -- in Ruby -- for you to examine.