The gs-apng gem continues the good work of James Pozdena and Paul Gebheim with some key enhancements including automatic message truncation, correct UTF-8 handling, rails-independent JSON encoding, full 256 byte message support, more failsafes and logging.
Automatic truncation of the alert message to fit the notification within the 256 byte limit. Two truncation options, on word breaks and strinctly on the character limit. UTF-8 is fully supported, in particular messages with asian characters should truncate correctly. There a bunch of test cases to prove it.
Truncation is actually extremely important as Apple will simply ignore your notification if it is over the limit, and according to the docs abort the sending of additional notifications in the block. This allows you to get the most out of your 256 byte limit without needing to worry about the size. Furthermore, an exception is thrown if it is not possible to fit the entire message within the limit (can happen if your server payload is too big) alerting you to the problem during development (better than dying silently).
Correctly handles UTF-8, which currently the justin.tv gem does not. This has been extensively tested. Also fully supports characters outside the Basic Multilingual Pain in versions all versions of rails (not just 3.2.13 and 4.0 which recently fixed that support in JSON).
Handles 256 byte messages, 1 extra byte over apns/jtv-apns (that’s 0.3% more data you can send!). Hey, every byte counts! Incidentally if anyone from the other apns gems want that fix, change the pack line in packaged_notification to
[0, 32, pt, pm.bytesize, pm].pack("cna*na*") which correctly encodes the value 256 in the two bytes provided.
The gem also uses Apple’s new ‘enhanced’ notification protocol allow you to specify and expiry for the notification. This is an optional expiry you can give your notification so that it won’t be transmitted to the user after a certain date.
Also a word of warning, unless you port this commit the jtv-apns APNS gem will not handle unicode correctly in Rails 3.2.13 and 4.0 due to changes in how rails encodes unicode in JSON, and a bug in jtv-apns UTF-8 handling.
This update is a drop-in replacement, and should be API compatible with jtv-apns from justintv/APNS.
As part of my work for Geospike, we need this gem and so I’ll be maintaining my fork going forward. If you’re interested in becoming a co-maintainer with me, please drop me a line. On the todo list: watch for responses from the enhanced notification system, and add yet more test-cases.