9

To detect invalid tokens, how often should I check the feedback service?

I have implemented a broadcasting system using the APNS service. I open a connection, send all the APNS messages, and disconnect. I then open a feedback connection right after the broadcast completes, and read any invalid tokens.

I do get invalid tokens on the feedback connection. However, often my broadcast will only partially succeed (some devices receive and others do not), and when I remove all but the known-good tokens, my test devices consistently receive the message.

I assume that means Apple is stopping the broadcast after it receives the first few invalid tokens.

So am I not listening on the Feedback properly?

1
  • 2
    After further investigation, I discovered that after sending a single token that Apple did not like (the format was OK, indistinguishable from a normal token), they disconnected me. Jun 7, 2012 at 19:38

2 Answers 2

3

In the end, the only way to properly handle this problem was to move to Apple's newer "enhanced notification format". This format allows you to provide an ID to each message you send, and when Apple disconnects you, they send you the error and the ID of the message that caused the error.

This allows for the client to properly retry already sent messages, and drop the token that was invalid

2

You should check the feedback response every time you send a push and delete inactive devices. Although, this does not look like your problem right now.

Your problem looks like you have some invalid tokens in your database. Apple will drop your connection if you send invalid tokens. Sending an inactive token will have no effect, but if you send a malformed/invalid token, Apple will kill your socket.

The other problem could be a missing retry scheme on your side. Did you implement any routine that will re-open the connection with Apple if it drops while you push ? You have to predict that the connection can fail, and if it does, you have to put it back up and start pushing again from where you stopped.

What you should look for is:

  • Make sure you only stock VALID tokens in your database
  • Make sure you have a retry scheme in place
  • Take a look at Notnoop, it is a very simple Java API that handles a lot for you
1
  • Thanks, the tokens all seem valid, however. They were all from Apple devices, with the same valid format. A retry scheme is impossible because Apple gives no feedback about when they disconnected my socket. Because it can take 100ms or so to close the socket, I may have sent hundreds of notifications by then. Jun 7, 2012 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.