We use the npm apn package with our Meteor app. We looked at the apnagent (because of the same textbook), but went with the apn because of its greater popularity. Although apnagent should also work well in your Meteor application, you can try apn only for troubleshooting.
We install it on the server side, like this ...
var apn = Meteor.require("apn"), path = Npm.require('path'), apnOptions = Meteor.settings.apnOptions || {}, alertSound = apnOptions.sound || "alert.aiff", apnConnection // default apn connection options apnOptions = _.extend({ cert: path.join(appRootPath, "private", "cert.pem"), key: path.join(appRootPath, "private", "key.pem"), }, apnOptions) apnConnection = new apn.Connection(apnOptions)
... and use it as follows:
sendAppleNotifications: function (alert, url, pushIds) { var note = new apn.Notification() // expires 1 hour from now note.expiry = Math.floor(Date.now() / 1000) + 3600 note.sound = alertSound note.alert = alert note.payload = {'url': url} _.each(pushIds, function (token) { var device = new apn.Device(token) apnConnection.pushNotification(note, device) }) return {success:'ok'} }, // end sendAppleNotifications
Please note that Meteor.require activated by the npm meteor npm , which you can read here . Alternatively, you can simply put your code that uses the apn package in your own Meteor package and use Npm.require as @GeoffreyBooth .
==
June 20, 2015 - Update
I recently answered a question about device tokens; hope these resources are helpful:
alanning
source share