Last active
December 24, 2015 12:29
-
-
Save ChrisRisner/6798293 to your computer and use it in GitHub Desktop.
Strikepoint
This file contains hidden or 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
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); | |
} | |
}); | |
}); | |
} | |
}); | |
} |
This file contains hidden or 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
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