Cocoa in the Shell

MacGPusher: Easy APNS in C++

Recently I had a problem with a Python library I used to send Apple Push Notifications (APN). It was not my code and I was way to lazy to try and debug it. Also, I always wanted to send push via a nice clean C/C++ code (I love native code.), but I never took the time to code it, so it was a good opportunity.

So, I made a small project that does just this. The code is standard C++11, so it runs on Linux/UNIX/OS X, perfect if you want to use it on a Linux server for example.

This project only communicate with APNS, that is opening a SSL connection and sending a formatted payload to a device. It is composed of 5 classes :

  • MMGSSLConnection Socket / SSL stuff
  • MMGAPNSConnection Subclass of MMGSSLConnection, send a payload to a given device
  • MMGDevice Simple class that represents an iOS device (token + badge number)
  • MMGPayload Simple class to represent a payload (Message, slider label, sound name, badge number)
  • MMGTools A set of static helper methods

Getting a list of devices is your job, for example I’m using this project along with libmysqlclient to fetch my list of devices from a MySQL database. Sending a notification to ~100k devices is very fast.

This project is currently missing the implementation for the Feedback service (I’m still using a php script for that..)

Also, there is no Makefile, making these is kinda a hassle for me, so if someone want to make a pull request, you are welcome :)
If you are not using an OS X machine, you need to compile it yourself with GCC (4.7 or higher, because of C++11) or clang, see the readme on github.

As usual the code is available on github and is released under the Simplified BSD License.

Tags: ,