Skip to content

Instantly share code, notes, and snippets.

@hyperh
Last active May 20, 2016 06:48
Show Gist options
  • Save hyperh/049b18389bd65548e1302cc15ab9b886 to your computer and use it in GitHub Desktop.
Save hyperh/049b18389bd65548e1302cc15ab9b886 to your computer and use it in GitHub Desktop.
Sending an APN from Meteor server
import _ from 'lodash';
const SEND_APN_MSG = 'notifications.send.APNMsg';
Meteor.methods({
'notifications.send.APNMsg'({sendToUserId}) {
check(arguments[0], {
sendToUserId: String,
});
const user = Meteor.users.findOne(sendToUserId);
user.pushToDevices.forEach(device => {
const token = device.token;
agent.createMessage()
.set({
extra: 123,
})
.device(token)
.alert('This is an alert')
.send(function (err) {
if (err) { throw new Meteor.Error(SEND_APN_MSG, err.message); }
else { console.log('APN msg sent successfully!'); }
});
});
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment