I’ve recently been working on developing an iOS application for Sirportly  — a helpdesk product which we run & develop at aTech. As part of this application, it became necessary for the Sirportly application to be able to send push notifications to users iOS devices.

The Apple Push Notification Service

The Apple Push Notification Service (or APNS for short) is a service provided by Apple to iOS developers to enable them to send notifications to any iOS device which has installed their application. In order to do this, your service-side application must open a secure connection to the APNS service and send any notifications in binary across this persistent connection. Unfortunately, many developers are unfamiliar with this technology and more happy working with HTTP APIs. There is also the additional overhead of worrying about maintaining persistent connections to Apple to avoid being blacklisted for repeated re-connections.

Introducing APNS Proxy...

The APNS proxy is an open source Rails application which handles all the connections to the APNS service and allows you to send your notifications to a familiar HTTP endpoint. Other key features include:

  • A nice web-based admin interface for managing your service & monitoring the sending of your notifications

  • Monitoring of the Apple Feedback channels to ensure that devices which uninstall your application are no longer delivered notifications.

  • Ability to support multiple applications with multiple environments and authentication keys.


How can I use it?

Full documentation about using the APNS Proxy is provided within the repository’s README. This includes information about installing the server software and using the API to deliver notifications to it.

It’s pretty simple to get started. It only took a few seconds for me to deploy a new instances for my own use to Viaduct.

Sending notifications to APNS Proxy from Ruby

I’ve also made APNS Client which is a Ruby library which can send messages to your APNS Proxy server. Once you’ve installed this, sending a notification from a Ruby application is as simple as this:

require 'apns'

# Create a client object
client = APNS::Client.new('https://apns.company.com', auth_key)

# Make a notification
notification = APNS::Notification.new  
notification.alert_body = 'Hello World!'

# Send the notification to the device token
client.notify(device_token, notification)

Converting your P12 and CER files to a suitable format

If you follow Apple guidance and create a private key using Keychain Access, you’ll be presented with a P12 private key file. You will also have a CER file from Apple once you have uploaded your signing request. The APNS Proxy service needs these keys to be provided in PEM format.

To help with this conversion, I’ve made a small command line utility called apns-key-convert which takes your two key files and spits out a PEM file which you can just upload into the appropriate APNS Proxy environment.

Tell us how you feel about this post?