Friday 14 June 2013

Push Notification

Push notifications to IOS devices

JavaPNS, so far the best library available in java. I have been using this in one of my projects and we have been so successful with that. I have a service that runs for every 20 min and reads around 400k records from mysql and iterates over and over and send pushes in batches.
Before you integrate this library, I suggest you to take a look at apple push notification docs. Its very important to understand the underlying behavior of notifications.


In particular, You should know what happen if you send a push notification to an erroneous push token(ie, push token that doesn't exist ) and how push token errors are handled in these libraries 



Example to send pushes using multithreads

numberOfThreads = Enable multithreading and allows us to send large number of push notifications concurrently


Apple doc says that its possible to send 9000 pushes/sec. JavaPNS  library has the ability to send large number of pushes at a time using thread mechanism. But to achieve somewhere closer to that count, It takes more than the brilliance of this library. Its up to the developer, If you would have read the above links, you can clearly get a picture of what I am taking about. Its about push token error handling logic.

There are two types of error handling in push notifications.
a) Handling erroneous push tokens(tokens that doesn't exist, ie, If user uninstall an app, token mapped to that app deosn't exist anymore, its invalid )
b) Retry and send rest of the notifications after a failure because of invalid push tokens.

Type(b) is already handled in javapns library, it has an exceptional way of handling errors. Now, the developer job is to handle type(a) properly.

To handle type(b), As a developer, when you are sending a bulk of push notifications, ignore all invalid push tokens and push everything in to a List
Next, Implement Feedback service. Its must, run feedback service on daily basis and remove invalid push tokens from your database to prevent sending pushes to invalid tokens.

Download JavaPNS library https://code.google.com/p/javapns/



Push notifications to Android devices

Server side implementation to send push notification to android devices

Add the below dependency in pom.xml



No comments:

Post a Comment