title: Use Apple Push Notification Service through Java
body: <p>Am trying to implement a Java program which sends an Apple Push Notification to an iPhone client app... Found the following library: <a href="http://code.google.com/p/javapns/" rel="nofollow noreferrer">Java APNs</a></p>
  
  <h2>Provider code:</h2>
  
  <p>Created the following code (from Javapns) to use in my app:</p>
  
  <pre><code>try {
      PayLoad payLoad = new PayLoad();
  
      payLoad.addAlert("My alert message");
      payLoad.addBadge(45);
      payLoad.addSound("default");
  
      PushNotificationManager pushManager = PushNotificationManager.getInstance();
      pushManager.addDevice("iPhone", "f4201f5d8278fe39545349d0868a24a3b60ed732");
      log.warn("Initializing connectiong with APNS...");
  
      // Connect to APNs
      pushManager.initializeConnection(HOST, PORT, 
                                   "/etc/Certificates.p12", "password", 
      SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
  
      Device client = pushManager.getDevice("Lambo");
  
      // Send Push
      log.warn("Sending push notification...");
      PushNotificationManager.getInstance().sendNotification(client, payLoad);
   }
   catch (Exception e) {
      throw new ApnsPushNotificationException("Unable to send push " + e);
   }
  </code></pre>
  
  <p>When I run this app (as you can see through the Log4j statements) there's no exceptions which occur:</p>
  
  <pre><code>  WARN  [MyCode] Initializing connectiong with APNS...
    WARN  [MyCode] Sending push notification...
  </code></pre>
  
  <p>But my client app doesn't receive any notifications!</p>
  
  <h2>IDPP Registration Process:</h2>
  
  <p>Also, did the following on the iPhone Developer Program Portal (IDPP):</p>
  
  <ul>
  <li><p>Created the APNS based SSL Certificate and Keys</p></li>
  <li><p>Created and installed the provisioning profile</p></li>
  <li><p>Installed the SSL Certificate and Key on the server.</p></li>
  </ul>
  
  <p>Have read over the Apple Push Notification Service Guide several times and noticed a few things:</p>
  
  <p>(1) On page 15, it states that the device token is not the same as the device UDID (which I am currently incorrectly passing in as the second parameter inside the PushNotificationManager.addDevice() method (see above)).</p>
  
  <p>On page 17, it states:</p>
  
  <p>"APNs generates a device token using information contained in the unique device certificate. The device token contains an identifier of the device. It then encrypts the device token with a token key and returns it to the device. The device returns the device token to the requesting application as an NSData object. The application then must deliver the device token to its provider in either binary or hexidecimal format."</p>
  
  <h2>iPhone OS Client Implementation</h2>
  
  <p>(2) After reading pages 33 - 34, I discovered that I didn't include the Objective-C code to have the app register with APNs.</p>
  
  <p>Am not an Objective-C developer, so is this where I can recover the device code or do I have to get it from the certificate?</p>
  
  <p>Where do I obtain the device token (sorry, someone else wrote the Objective-C client app and I am a Java Developer)?</p>
  
  <p>Question(s):</p>
  
  <p>(1) With the exception of not knowing where to get the device token and the mobile client code registration, is there anything else that I have not looked over or missed?</p>
  
  <p>(2) Am I using the Javapns library the right way?</p>
  
  <p>Thank you for taking the time to read this...</p>