ApnsService.push(Collection<String> deviceTokens, String payload) Problem

566 views
Skip to first unread message

Mr. Creosote

unread,
Aug 20, 2011, 5:23:33 PM8/20/11
to Java client for Apple Push Notification service (APNs)
I'm using the ApnsService.push(Collection<String> deviceTokens, String
payload) method in release 0.1.5 and encountering a problem.

I have 3 device tokens: token1, token2, and token3. Token3 is either
a production token (I'm doing this in the Sandbox environment) or in
some way invalid. I've tried using a call to
service.getInactiveDevices(), but the returned collection is empty.

1. I build an ArrayList containing the tokens in order 1, 2, 3 and
invoke the push method. Devices 1 and 2 receive notifications.

2. I build an ArrayList containing the tokens in order 1, 3, 2 and
invoke the push method. Device 1 receives a notification, but Device
2 does not.

3. I build an ArrayList containing the tokens in order 3, 1, 2 and
invoke the push method. No devices receive a notification.

In none of the cases is an exception being thrown.

My conclusion is that the push method is choking on the invalid token
and not moving on the next item(s) in the list.

Is anyone else using this method and seeing this? Is there a
workaround?

Mahmood Ali

unread,
Aug 22, 2011, 12:07:47 AM8/22/11
to java-apn...@googlegroups.com
Greetings Mr. Creosote,

This is a known issue and a main annoyance with the Apple APNs protocol, this is not a library issue. Basically you should ensure that any device token you send is a valid device token, otherwise Apple may reject the tokens and treats your notification sender as untrusted.

Couple of points:
1. service.getInactiveDevices() returns inactive devices, where the user installed the app but disabled it afterwards. It does not return invalid device tokens.
2. ApnsDelegate has a callback method (connectionClosed) that returns an error code. If you use an invalid notification id, the callback method will be called with INVALID_TOKEN argument along with the message id. You may retry the messages sent after. The API isn't quite user-friendly yet, but it got slightly improved with 0.2.0 already.

Your best bet is to ensure that all the device tokens are valid tokens and properly marked whether they are production or sandbox.

Regards,- Mahmood

Reply all
Reply to author
Forward
0 new messages