Skip to content

Instantly share code, notes, and snippets.

@ChrisRisner
Last active December 24, 2015 12:29
Show Gist options
  • Save ChrisRisner/6798293 to your computer and use it in GitHub Desktop.
Save ChrisRisner/6798293 to your computer and use it in GitHub Desktop.
Strikepoint
function update(item, user, request) {
request.execute({
success: function(){
request.respond();
sendNotifications(item);
},
error: function(err){
request.respond(500, "Error");
}
});
}
function sendNotifications(item){
var tokenTable = tables.getTable('PushInfo');
tokenTable.read({
success: function(tokens){
tokens.forEach(function(token){
push.apns.send(token.token, {
alert: "Values set!",
badge: 1
}
, {
success: function(response){
console.log(response);
},
error: function(err){
console.error(err);
}
});
});
}
});
}
function insert(item, user, request) {
var pushInfoTable = tables.getTable('PushInfo');
pushInfoTable
.where({ token: item.token })
.read({ success: insertTokenIfNotFound });
function insertTokenIfNotFound(existingTokens) {
if (existingTokens.length > 0) {
request.respond(200, existingTokens[0]);
} else {
request.execute();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment