Saturday, April 28, 2012

Java : Apple Push Notification Server Side Coding

JavaPNS is a Java library to send notifications through the Apple Push Notification Service to iOS devices. Using JavaPNS, we can send Push notification in a single line of code.

For further details, refer site : http://code.google.com/p/javapns/
The Apple Push Notification Service is a service created by Apple Inc. 
iOS apps can provide three types of notifications:
  • Sounds: Plays an audible alert
  • Alerts/Banners: Displays an alert or banner on the screen
  • Badges: Displays an image or number on the application icon
 Before sending a notification from server, we need to have the following.
  1. Device Token of the device (IPhone/IPod).
  2. Private Key created from certificate.
  3. Have a password of the private key created.
Note: If the private key is not proper, SSLHandshakeException occurs

For Eg:
Java Code looks like
Push.alert(message, keystore, password, production, devices)



Push.alert("Hello World!", "keystore.p12", "keystore_password", false, "Your token");
Parameters:
message : Content to pass
keystore : Private key
password : Private key password
producation : If true, production else sandbox
devices : one or more device token, device token length is 64 digits. The device token is analogous to a phone number; it contains information that enables APNs to locate the device on which the client application is installed.

To run the server code, required jar files list
bcprov-1.45.jar
commons-io-1.3.jar
commons-logging-1.1.1.jar
JavaPNS_2.2.jar
log4j-1.2.16.jar


Thanks for reading :).
Whether this post is helpful?
Please leave a comment.

4 comments :

  1. Hi - I am following tutorial from https://github.com/notnoop/java-apns (send push notification to iOS device) and I used http://csnipp.com/s/153/-Simple-Apple-Push-Notification-Server class to send notifications using DeviceId, cert.p12 and password, but I don't see any error / exceptions coming or notifications coming. Could you please let me know what the problem is ?

    ReplyDelete
    Replies
    1. Use the callback's you can find the problem

      Delete
  2. Hey - Thank you. Could you please let me know how we can use callback?

    Thanks,
    Savani

    ReplyDelete
    Replies
    1. Have a look in https://code.google.com/p/javapns/wiki/ManagingPushErrors

      Delete