Late last night I came in from the office and gave Karen the iPad. I then sat down with my laptop, and sent her a message, like below. Proud as punch, I was!
"Stop dicking about it's the climax of Miss Marple!"
Seriously, what do you have to do to impress a woman nowadays. Did she not realise it took me two hours of "dicking about" with SSL certificates, Provisioning Profiles, secret keys and the like to get that to work!
Notice in the image above there's an app (row 2 column 2) called NotificationTest with an "unread" count of 2. This is the app I made. The app isn't actually running on the iPad, but if you were to press the View button it would launch and action the message in some way. That's how push notifications work.
If you're not a smart phone user you might not have seen a push notification before. If you do use an iPhone, an Android or Blackberry you're probably familiar with the notices popping up to tell you it's your move on Words With Friends or that somebody mentioned you on Twitter.
They're a useful way of "engaging" your users. I say engaging. Potentially they could be annoying. Look at how many other apps want to push things in my face:
Why would Angelina Ballerina or Talking Tom want to send me push notifications?
There's a potential for spam, as I see it, but, for now, if used properly, they can be really useful. You can of course disable them either completely or by application.
Apple have made improvements in iOS5 to the way notifications work to make them more like Android's -- less in your face and easier to manage. Like them or loathe them they're here to stay.
How Did I Do It?
Here's what you need in order to do what I did and add them to your app:
- An Apple Mac (massively over-priced).
- A copy of Appcelerator's Titanium Studio (free).
- An enrolment in the Apple Developer Program (paid)
- An account with Urban Airship (free).
- Patience, guess-work and a few hours to spare (free?).
To get it working I first Googled "titanium urban airship" and quickly found a good tutorial to get me started. What followed was a couple of hours creating and importing SSL certificates, rebuilding and re-installing over and over again (you can only test on the actual device!).
A lot of what followed involved encountering an error, Googling it and applying the suggested solution. But, isn't that what being a developer is about nowadays?
A couple of gotchas that caught me out:
- You'll need a new Provisioning Profile tied to the new app's ID, rather than a generic one.
- The App "key" and "secret" referred to in the sample code are from Urban Airship. You need to register your app on there and copy the key and secrets over.
How Do They Work?
While I got them to work and the geek in me was satisfied with that. The true geek in me isn't completely satisfied. How do they actually work!? How does it know where my device is? Who is actually sending the notification - Apple or Urban Airship?
Anybody know the exact path the packets take to get to the intended device?