Last active
May 20, 2016 06:48
-
-
Save hyperh/049b18389bd65548e1302cc15ab9b886 to your computer and use it in GitHub Desktop.
Sending an APN from Meteor server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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