Phil Calçado
Phil Calçado

Reputation: 470

Apple Push Notifications Service ( APNS ): Feedback Service Response has missing byte?

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: APNS Feedback Format

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 =/

Upvotes: 1

Views: 1417

Answers (2)

muccy
muccy

Reputation: 111

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

Upvotes: 2

Mark Granoff
Mark Granoff

Reputation: 16938

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.

Upvotes: 0

Related Questions