Communication-wise push notifications are one of my personal favorite features on any mobile device platform So, it seems natural to write a bit about it. This time we will see how to use a third-party (but still free) service in the cloud to handle the push notifications for us (independent of Apple, Google, Blackberry or Microsoft). The sample shown here in this blog entry is for iOS and is written and built in C# with MonoTouch.

Although, the ideas of push notifications are similar between iOS; Windows Phone 7 and other device platforms, there are differences in implementation (and partly in architecture). What I wanted to achieve for my push notification-enabled apps was two-folded:

Being able to easily scale out and handle potentially huge numbers of user/subscribers and push messages without having to write, host and maintain my own code and services and servers

Not having to implement push notifications logic (like register, unregistering, receiving, error handling etc) for each and every platform over and over

Use a cloud service offered by an independent third party. In my case this is Urban Airship (free for 1,000,000 messages per month)

Rock da cloud.

Turns out that Urban Airship has a web-friendly REST API (oh wonder!) which accepts JSON messages. Honestly, it was not hard to decide to write some C# to utilize this service instead of having to deal with Apple’s APNs directly.

Note: the code illustrated here is a bit outdated. It relies on some iOS intrinsics like UIApplication and NSUserDefaults and therefore is not portable across devices. I have some platform-independent code lurking here but need to fully implement, test and polish it first.

The most important piece of code is the PushNotifications class which handles all the necessary communication, especially with the Urban Airship service: