Is there a sample project showing how to use APNS on the IPhone and how to set up things? I’m currently looking at the documentation but it would be nice to have some working code to pick apart and see how it all works together?
I can’t seem to find anything using google or in the iphone dev center.
The worst part about setting up the push notification service is the provisioning. The major stumbling block that I came across was that there is a certificate and a key in the .cer file you download from Apple’s site, I wrote a system service in C# that sent out notifications and the connections kept failing because I had exported the certificate and not the key.
I don’t recall who originally wrote this, here is a little bit of code in python that helped me out when I was first testing the notification service. I like it because it is very simple and works well during testing.
There’s also a rails gem called apn_on_rails that seems to work pretty well if you’re developing a rails application, I just saw it today and was able to send out notifications from the console.
On the iPhone side you’ll just need to call the following to register for all types of notifications:
To receive the device token you’ll need to implement the following delegate methods:
During testing you can just kick the deviceToken to the console with NSLog, then paste it into the python script above, in production you’ll obviously need to set up some method to get the token to your servers.
Also, in production you’ll need to query Apple’s feedback service and remove device tokens from users who removed your app.