Posts Tagged ‘iphone’
Apple Push Notification Service & Java
If you look at the documentation for APNS, it is relatively straightforward. The main thing that is probably new to many Java developers is setting up the SSL connection.
Assuming you have followed the documentation from Apple, you should have a certificate for your Push App, as well as a private key. Export each of these individually into a ‘p12′ file, then cat them together. Not sure if order matters here, I put the certificate first.
KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(getClass().getResourceAsStream(P12FILE), KEYPASS.toCharArray())
KeyManagerFactory keyMgrFactory = KeyManagerFactory.getInstance("SunX509");
keyMgrFactory.init(keyStore, KEYPASS.toCharArray());
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyMgrFactory.getKeyManagers(), null, null);
sslSocketFactory = sslContext.getSocketFactory();
sslSocket = (SSLSocket)sslSocketFactory.createSocket(HOST, PORT);
def cipherSuites = sslSocket.getSupportedCipherSuites();
sslSocket.setEnabledCipherSuites(cipherSuites);
sslSocket.startHandshake();
After this, you can grab the output stream of the socket and write to it. This is what works for me, of course there’s more to managing the socket, but this is the part that was not entirely obvious. You still have to encode your bytes correctly; the service is not very forgiving if you do it wrong. And without any response, you need to pay close attention to what you’re doing!
Weightbot
I purchased Weightbot today, not because I necessarily wanted to track my weight in detail (although I do have a goal). I bought it to take a look at the app itself. IMO, it epitomizes what an iPhone app should be. Simple, does one thing very well, and fun to use.
While I think the basic Cocoa touch apps have a nice default look and feel, it is also interesting to see an app like this which basically uses very little (or none?) of the standard widgets.
Kudos to these guys for a great app, I’m sure they will be getting a ton of downloads as the New Year approaches.